2013-01-09 125 views
1

我試圖打開新窗口併發送表單數據與JavaScript和jquery-1.8.3。Tryied window.open與Ajax,window.print不工作(IE9)

在Bernhard的幫助下,我成功地用頁面打電話給一個新窗口打印。

(謝謝你這麼多伯恩哈德。window.open and sending form data not working

但是,window.print()功能不會在IE9工作! (FF,Chorme做的很好)

我刷新頁面,然後調用IE9 window.print()

這裏是源代碼。

<a href="#" onclick="printPage()">Print this</a> 

<script type="text/javascript" src="/common/js/jquery-1.8.3.min.js"></script> 
<script type="text/javascript"> 

function printPage(){ 

    $.post('/common/print.jsp', {view:$("#ctn").html()}).success(function(response){ 
     var oWindow = window.open('', "printWindow", "width=700px,height=800px"); 
     oWindow.document.write(response); 
     oWindow.print(); // I added this line. But IE9 not working. 
    }); 
} 
</script> 

有什麼我錯過了嗎?

回答

1

試試這個:

$.post('/common/print.jsp', {view:$("#ctn").html()}).success(function(response){ 
     var oWindow = window.open('', "printWindow", "width=700px,height=800px"); 
     oWindow.document.write(response); 
     oWindow.document.close(); 
     oWindow.focus(); 
     oWindow.print(); // I added this line. But IE9 not working. 
    }); 

結帳這樣的:

Using HTTP Headers to Force Standards View in Internet Explorer 8 and Above

您還可以使用元標籤強制標準模式。 X-UA-Compatible meta tag告訴Internet Explorer要使用或模擬的視圖模式。

By setting this meta tag, you tell IE to use standards mode even if there are comments or an XML declaration above the DOCTYPE.determine what version of Internet Explorer can best view the page,然後設置元標記以定義該版本。

IE 7: 

<meta http-equiv="X-UA-Compatible" value="IE=7"> 

IE 8: 

<meta http-equiv="X-UA-Compatible" value="IE=8"> 

IE 9: 

<meta http-equiv="X-UA-Compatible" value="IE=9"> 

如果一個顧客來以更高的視圖模式中的頁面比它支持 (例如,IE 7瀏覽器查看網頁請求IE8視圖模式),它 將忽略標記並呈現頁面的模式,它會有 沒有標籤。

更多信息在這裏找到:http://webdesign.about.com/od/internetexplorer/qt/force-compatibility-view-in-ie.htm

+0

謝謝您的回答,但我已經tryied。沒有發生。 –

+0

有沒有強迫compability的觀點? –

+1

結帳這一個:http://webdesign.about.com/od/internetexplorer/qt/force-compatibility-view-in-ie.htm – Jai