I have a page that is supposed to launch the Print Preview page onload.
I found this:
var OLECMDID = 7;
/* OLECMDID values:
* 6 - print
* 7 - print preview
* 1 - open window
* 4 - Save As
*/
var PROMPT = 1; // 2 DONTPROMPTUSER
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
WebBrowser1.ExecWB(OLECMDID, PROMPT);
WebBrowser1.outerHTML = "";
But...
- it does not work in FireFox.
- it's kind of ugly.
Is there a better way for IE or a way that works for FireFox?
-
You can't, Print Preview is a feature of a browser, and therefore should be protected from being called by JavaScript as it would be a security risk.
That's why your example uses Active X, which bypasses the JavaScript security issues.
So instead use the print stylesheet that you already should have and show it for media=screen,print instead of media=print.
Read Alist Apart: Going to Print for a good article on the subject of print stylesheets.
Thomas : The article on ALA has moved: http://www.alistapart.com/articles/goingtoprint/From Pacifika -
I think the best that's possible in cross-browser JavaScript is
window.print(), which (in Firefox 3, for me) brings up the 'print' dialog and not the print preview dialog.From Phill Sacre -
checkout: http://www.alistapart.com/articles/printtopreview/
From George Birbilis
0 comments:
Post a Comment