【问题标题】:Tryied window.open with Ajax, window.print not working (IE9)尝试使用 Ajax 打开 window.open,window.print 不起作用(IE9)
【发布时间】:2013-01-09 05:57:45
【问题描述】:

我正在尝试使用 javascript 和 jquery-1.8.3 打开新窗口并发送表单数据。

在 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>

我错过了什么吗?

【问题讨论】:

    标签: javascript jquery


    【解决方案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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-30
    相关资源
    最近更新 更多