在window.open之后,无法在Mac的Safari中打印 [英] After window.open, can't print in Safari for Mac

查看:210
本文介绍了在window.open之后,无法在Mac的Safari中打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用window.open函数使用Javascript代码创建辅助浏览器窗口,并以编程方式填充一些HTML内容.它适用于我的应用程序支持的所有浏览器,但以下浏览器除外:Mac上的Safari.实际上,窗口本身可以,但是打印命令被禁用.有人知道为什么吗?我应该提到显示此窗口的主要原因是允许用户打印一些数据.我想我可以在页面中实现打印"按钮,但我不希望这样做(它可能也不起作用,但我没有尝试过).

I create a secondary browser window with Javascript code, using the window.open function, and fill it programmatically with some HTML content. It works well for all browsers that my application supports except for one: Safari on Mac. In fact, the window itself is OK but the print command is disabled. Does anybody have an idea why? I should mention that the main reason to show this window is to allow the users to print some data. I guess I could implement a "Print" button in the page but I would prefer not to (and it may not work either, but I haven't tried it).

这是我用来创建HTML内容的代码的简化示例:

Here is a simplified example of the code that I use to create the HTML content:

        var pp = window.open("", "_blank");
        pp.document.writeln("<html>");
        pp.document.writeln("<head>");
        pp.document.writeln("<title>");
        pp.document.writeln("Hello");
        pp.document.writeln("</title>");
        pp.document.writeln("</head>");
        pp.document.writeln("<body>");
        pp.document.writeln("The body");
        pp.document.writeln("</html>");
        pp.document.close();

我尝试过围绕该代码进行变体,但没有成功.我的测试是使用Mac OS X 10.6.8上的Safari 5.1完成的.欢迎任何帮助!

I tried variations around that code, without any success. My tests are done with Safari 5.1 on Mac OS X 10.6.8. Any help is welcome!

推荐答案

自行打印窗口:

在添加</html>之前:

pp.document.writeln("<script type='text/javascript'>window.print()</script>");

这篇关于在window.open之后,无法在Mac的Safari中打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆