javascript window.print() 的 Safari 打印问题 [英] Safari print issue with javascript window.print()

查看:17
本文介绍了javascript window.print() 的 Safari 打印问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Safari 上遇到打印问题.我的系统是 Windows 7,这个功能在除 Safari 之外的所有其他浏览器中都可以正常工作.情况如下:

I am having an issue with print on Safari. My System is Windows 7, and this function works fine in all other browsers except Safari. Here is the situation:

window.onload = function(){
    console.log('before print');
    window.print();
}

控制台不会输出日志,但会先出现打印页面,在打印页面选择取消后,会输出日志.

It won't output the log in console panel, but the print page will appear first, after i choose cancel in print page, the log will be output.

有没有机构提出这个问题?任何帮助将不胜感激.

Does any body came up with this issue? Any help will be appreciated.

更新

这是我遇到的情况:我们需要打印一个用户可以通过选中和取消选中复选框来更改其内容的页面,并且只打印该页面的内容部分,因此我们创建了一个仅包含打印内容的新页面.在这个页面中,我们需要隐藏用户没有选择的不必要的内容,所以我们需要在window.print()被调用之前做一些DOM操作.console.log() 只是观察的示例代码.我尝试在测试 HTML 中添加 <div id='test'>Test HTML</div> 并添加

Here is the situation i have: We need to print a page whose content can be changed by user by checking and unchecking check box, and only the content part of this page should be printed, so we create a new page that only contains the content for printing. In this page, we need to hide the unnecessary content that is not selected by user, so we need to do some DOM operation before window.print() get called. The console.log() is just an example code for observing. I tried to add an <div id='test'>Test HTML</div> in test HTML and add

var test = document.getElementById('test');
test.style.background = 'yellow';

window.print(); 之前,它在我的 Safari 浏览器中显示相同的结果,在我单击打印面板中的取消按钮之前,测试 HTML"不会变成黄色,所以它不是只是 console.log 问题.

before window.print();, it shows the same result in my Safari browser, the 'Test HTML' will not turn to yellow until i click cancel button in print panel, so it's not just the console.log issue.

更新

我在 Windows 7 上使用 Safari 5.1.7(7534.57.2)

I am using Safari 5.1.7(7534.57.2) on Windows 7

推荐答案

经过多次尝试,下面的代码有效,但我不知道原因,谁能解释一下?或者这是一个 Safari 错误?

After several times trying, below code works, but i don't know the reason, can anybody explain? Or this is a Safari Bug?

window.onload = function() {
    $('body').html('After change');
    setTimeout(window.print, 1000);
};

这篇关于javascript window.print() 的 Safari 打印问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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