admin管理员组文章数量:1245029
I want to open one word document using JavaScript as well as open print dialogue box for that opened document window.
Here is my code.
window.open('');
window.print();
It works, but the print dialogue gets opened for the current window, not the newly opened window. How do I do it?
I want to open one word document using JavaScript as well as open print dialogue box for that opened document window.
Here is my code.
window.open('http://www.tizaq.');
window.print();
It works, but the print dialogue gets opened for the current window, not the newly opened window. How do I do it?
Share Improve this question edited Mar 7, 2014 at 17:40 tshepang 12.5k25 gold badges97 silver badges139 bronze badges asked Apr 15, 2011 at 8:54 CoderCoder 511 gold badge2 silver badges3 bronze badges2 Answers
Reset to default 13Call print
on the new window rather than the old:
var wnd = window.open('http://stackoverflow.');
wnd.print();
I don't like your odds, though, of it not falling afoul of browser security. :-) The "external" window object may well not support print
(window
objects e in two types, the "external" type that other windows have access to, and the "internal" type that references itself, which has more permissions, etc.) At the least, you'll probably have to wait for the load event, but I best in general it's going to be tricky.
It seems to work for documents with the same origin, so the Same Origin Policy is a factor. That example crashes in IE6 (literally crashes the browser), but works for me in IE7 on Windows, and Chrome and Firefox 3.6 on Linux (and not in Opera 11 on Linux). Probably wouldn't hurt to put a delay / yield in there, e.g.:
var wnd = window.open(your_path_here);
setTimeout(function() {
wnd.print();
}, 0);
You said "word document" in your question, but your example looks like a website. I have no idea whether this would work if you were opening a Microsoft Word document by loading it into a browser window.
Well, Better way
var my_window = window.open("", "mywindow1", "status=1,width=350,height=150");
my_window.document.write("<scr" + "ipt>window.location.href='http://stackoverflow.';window.print();</scr" + "ipt>");
try Like this or better to make another page using iframe for print
本文标签: printingHow to open a file with print dialogue box using JavaScriptStack Overflow
版权声明:本文标题:printing - How to open a file with print dialogue box using JavaScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740215834a2242844.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论