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

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

问题描述

我在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'>测试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 Bug?

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的Safari打印问题window.print()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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