2017-06-02 128 views
0

我想用自定義html內容打開彈出式窗口IE瀏覽器。使用提供Can I open a new window and populate it with a string variable?用IE瀏覽器自定義html內容打開新窗口

我用下面的JavaScript的答案片段:

var wnd = window.open("about:blank", "", ""); 
    wnd.document.write(htmlContent); 
    wnd.document.close(); 

這段代碼打開一個新標籤,而不是一個彈出窗口的內容,所以我用了額外的參數_blank作爲如下:

var wnd = window.open("about:blank", "", "_blank"); 
    wnd.document.write(htmlContent); 
    wnd.document.close(); 

現在,一個彈出我的內容打開,但它沒有滾動條,不調整大小,沒有菜單,由於其印刷是不可能的。我已經嘗試過的一種方法是使用windowfeatures參數,如下所示:

var strWindowFeatures = 
    "menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes"; 
    var wnd = window.open("about:blank", strWindowFeatures, "_blank"); 
    wnd.document.write(htmlContent); 
    wnd.document.close(); 

但是使用此參數對結果彈出窗口沒有影響。另外,在Chrome中,彈出窗口沒有內容。我怎麼解決這個問題?

回答

0

所以,我一直在嘗試自己和使用上MDN網站的window.open文檔

https://developer.mozilla.org/en-US/docs/Web/API/Window/open

我發現了以下解決方案:

var wnd = window.open("about:blank", "", 
"menubar,resizable,scrollbars,status"); 
    wnd.document.write(htmlContent); 
    wnd.document.close(); 

我在IE測試此代碼11並且彈出窗口具有html內容,可滾動和可調整大小,並且可以通過按下Alt鍵來訪問IE菜單。 重要此代碼不能在Chrome工作,爲Chrome一個可行的解決方案是:

window.open("data:text/html;charset=utf-8," + 
       htmlContent, "", "_blank"); 

我把這個解決方案從

Can I open a new window and populate it with a string variable?

相關問題