Pan*_*kaj 64 javascript printing internet-explorer
我在javascript中做这样的事情,点击链接打印我的页面的一部分
function printDiv() {
var divToPrint = document.getElementById('printArea');
var newWin = window.open();
newWin.document.write(divToPrint.innerHTML);
newWin.print();
newWin.close();
}
Run Code Online (Sandbox Code Playgroud)
它在Firefox中很好用,但在IE中却不行.
请有人帮忙
小智 133
之后添加这些行 newWin.document.write(divToPrint.innerHTML)
newWin.document.close();
newWin.focus();
newWin.print();
newWin.close();
Run Code Online (Sandbox Code Playgroud)
然后打印功能将在所有浏览器中工作...
Ted*_*Ted 10
添加newWin.document.close(); ,像这样:
function printDiv() {
var divToPrint = document.getElementById('printArea');
var newWin = window.open();
newWin.document.write(divToPrint.innerHTML);
newWin.document.close();
newWin.print();
newWin.close();
}
Run Code Online (Sandbox Code Playgroud)
这让IE很开心.HTH,-Ted
function printDiv() {
var divToPrint = document.getElementById('printArea');
newWin= window.open();
newWin.document.write(divToPrint.innerHTML);
newWin.location.reload();
newWin.focus();
newWin.print();
newWin.close();
}
Run Code Online (Sandbox Code Playgroud)
我不确定,但我认为这是由于 InternetExplorer 的安全规则而发生的......
如果您调用像 print() 这样的函数,它会手动询问用户是否要允许活动脚本编写,如果他单击黄色条并选择“是”,则会出现打印对话框。如果您单击“否”或只是不执行任何操作,则不会执行被视为活动脚本或其他安全相关 JavaScript 函数的部分。
在您的示例中,窗口打开,然后调用 print() ,弹出确认栏(没有选择任何内容,实际上由于时间短而无法选择任何内容),调用 newWin.close() ,窗口关闭。
您应该尝试将该页面添加到 InternetExplorer 中的受信任站点或更改安全设置。
javascript 本身可能有一种处理安全策略的方法,但我对 InternetExplorer 安全策略了解不多。
希望这可以帮助
归档时间: |
|
查看次数: |
107761 次 |
最近记录: |