鍍金池/ 問答/HTML5  HTML/ 通過iframe實現(xiàn)打印pdf,瀏覽器警告怎么辦?

通過iframe實現(xiàn)打印pdf,瀏覽器警告怎么辦?

我想通過iframe來打印一個pdf文件,但是有時候瀏覽器會警告 Resource interpreted as Document but transferred with MIME type application/pdf 。通過測試是能打印的,但是偶爾就會報這個警告不能打印,出現(xiàn)警告無規(guī)律,點幾次就出。

function test(){
     
      var  iframe = document.getElementById("printIframe");
      iframe.type="application/pdf";
      document.getElementById("printIframe").src = 'GWTJM.pdf';
 
      if (iframe.attachEvent){ 
            iframe.attachEvent("onload", function(){ 
              // alert("Local iframe is now loaded."); 
              document.getElementById("printIframe").contentWindow.print();
        }); 
        } else { 
        iframe.onload = function(){ 
             // alert("Local iframe is now loaded."); 
             document.getElementById("printIframe").contentWindow.print();
        }; 
     } 
       
    }

圖片描述

回答
編輯回答
編輯回答
初心

我也遇到這個問題 有什么解決辦法嗎

2018年6月23日 19:33