admin管理员组文章数量:1332345
I have the following js code:
window.print();
This works in Chrome and IE. It also works on iPhone safari. However, it does not work on Firefox.
The following does work in Firefox
alert()
window.print();
so I figure it's some kind of timing thing? Note that my js code only loads after the page itself has been loaded:
function loadJS() {
var element = document.createElement("script"); //
element.src = "url/js/all.js";
document.body.appendChild(element);
}
if (window.addEventListener)
window.addEventListener("load", loadJS, false);
else if (window.attachEvent)
window.attachEvent("onload", loadJS);
else
window.onload = loadJS;
I have the following js code:
window.print();
This works in Chrome and IE. It also works on iPhone safari. However, it does not work on Firefox.
The following does work in Firefox
alert()
window.print();
so I figure it's some kind of timing thing? Note that my js code only loads after the page itself has been loaded:
function loadJS() {
var element = document.createElement("script"); //
element.src = "url/js/all.js";
document.body.appendChild(element);
}
if (window.addEventListener)
window.addEventListener("load", loadJS, false);
else if (window.attachEvent)
window.attachEvent("onload", loadJS);
else
window.onload = loadJS;
Share
Improve this question
edited Sep 12, 2013 at 7:35
user984003
asked Sep 12, 2013 at 5:39
user984003user984003
29.6k69 gold badges202 silver badges315 bronze badges
8
- 2 have you checked...popups are blocked or not...??? – guri Commented Sep 12, 2013 at 5:42
- where are you calling window.print(); ..? – Sudhir Bastakoti Commented Sep 12, 2013 at 5:49
- It's called in my js code. It's NOT inside a onClick. The page loads, and then it's called. – user984003 Commented Sep 12, 2013 at 5:52
- 1 If pop-ups were blocked then I don't see how it would work when I include the alert() – user984003 Commented Sep 12, 2013 at 5:52
-
Can you show the whole loadJS function?
window.print()
works fine here, testing it in the dev console on FF-23.0.1. – Joe Simmons Commented Sep 12, 2013 at 6:22
1 Answer
Reset to default 4Well, just making it wait, worked, although it seems silly to have to do it. Plus, I don't know if this will always work...
setTimeout(
function() {
window.print();
}, 100);
本文标签: javascriptwindowprint() not working in FirefoxStack Overflow
版权声明:本文标题:javascript - window.print() not working in Firefox - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742325695a2453677.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论