gpt4 book ai didi

javascript - window.print() 在 IE7 和 IE8 中卡住

转载 作者:行者123 更新时间:2023-11-28 10:20:37 25 4
gpt4 key购买 nike

在一些页面上工作,主要是用经典的 asp 构建的。我正在尝试在我的一些页面上使用 window.print() 但由于某种原因它正在拖延我。它会弹出并询问要使用的打印机,选择并单击确定后....它停止运行并不得不结束 IE 任务。这是我的链接标签:

<a href="#" onclick="window.print(); return false;" >print window</a>

这在所有其他浏览器中运行良好。我唯一能想到的是我的 CSS 中有一个 @media 打印标签,我知道它没有得到完全支持。将此标记放在页面上会导致这种情况发生吗?

最佳答案

onclick="window.print();"本身就足够了——不需要 return false .由于您没有链接到任何地方,因此您应该使用 <button>而不是 anchor 。您还应该使用事件监听器而不是 onclick .

HTML:

<button type="button" id="print-page">Print</button>

JS:

var button = document.getElementById('print-page');

if (window.addEventListener) {
button.addEventListener('click', window.print, false);
}
else {
button.attachEvent('onclick', window.print);
}

如果您在设计 <button> 时遇到问题或 <input type="button">元素到你喜欢的(旧的浏览器可能很挑剔),你可以使用 <span>但一定要加上role="button"以便辅助技术和其他机器(搜索引擎等)知道该元素应该像按钮一样对待。

关于javascript - window.print() 在 IE7 和 IE8 中卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24025739/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com