By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,605 Members | 2,147 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,605 IT Pros & Developers. It's quick & easy.

window print preview called by javascript

P: 77
hello all, i want to call window print preview (in browser, File - Print Preview) by javascript, this is the code


Expand|Select|Wrap|Line Numbers
  1.     function printpreview()
  2.     {
  3.         var OLECMDID = 7;
  4.         /* OLECMDID values:
  5.         * 6 - print
  6.         * 7 - print preview
  7.         * 1 - open window
  8.         * 4 - Save As
  9.         */
  10.         var PROMPT = 1; // 2 DONTPROMPTUSER
  11.         var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
  12.         document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
  13.         WebBrowser1.ExecWB(OLECMDID, PROMPT);
  14.         WebBrowser1.outerHTML = "";
  15.     }


that function triggered by input type this one below

[HTML]<input type="button" name="printPrabp" id="printPrabp" onclick = "javascript:printpreview();" value="Print Preview" />
[/HTML]

but the browser shown an error "document.body.insertAdjacentHTML is not a function"

any idea please...
thanks

regards, maminx
Jul 25 '08 #1
Share this Question
Share on Google+
5 Replies


P: 77
hello all, i have a scipt to call window print preview by javascript below

Expand|Select|Wrap|Line Numbers
  1.     function printpreview()
  2.     {
  3.         var OLECMDID = 7;
  4.         /* OLECMDID values:
  5.         * 6 - print
  6.         * 7 - print preview
  7.         * 1 - open window
  8.         * 4 - Save As
  9.         */
  10.         var PROMPT = 1; // 2 DONTPROMPTUSER
  11.         var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
  12.         document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
  13.         WebBrowser1.ExecWB(OLECMDID, PROMPT);
  14.         WebBrowser1.outerHTML = "";
  15.     }
  16.  

but that's works only in IE, doesn';t works in mozilla. Mozilla shown an error "insertAdjacentHTML is not a function"

any idea to solve my problem??

thanks...

best regards,

maminx
Jul 28 '08 #2

gits
Expert Mod 5K+
P: 5,343
your code is IE-specific and i think every-browser implements its own print-preview handling ... for mozilla you may start further search from here

kind regards

PS: btw. please use CODE-Tags when posting source code ...
Jul 28 '08 #3

rohypnol
P: 54
Try to replace insertAdjacentElement with appendChild. I have no idea if the print preview will work. For more information, see this page: [deleted]
Jul 28 '08 #4

gits
Expert Mod 5K+
P: 5,343
Try to replace insertAdjacentElement with appendChild. I have no idea if the print preview will work. For more information, see this page: [deleted]
read here for why i removed the link ...

kind regards
MOD
Jul 28 '08 #5

gits
Expert Mod 5K+
P: 5,343
threads merged ... don't double post questions regarding the same issue!

regards,
MOD
Jul 28 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.