Posted by: hernk on: 13 April 2007
I found the script from jguru to call print preview from javascript.
I dont know whats the limitations, but its works perfectly as I expected.
Here is the script :
<html>
<head>
<title>Print Preview</title>
<script>
function printpr()
{
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 = “”;
}
</script>
</head>
<body>
<form>
<input type=’button’ value=”Print Preview” onclick=”printpr();”>
</form>
</body>
</html>
Thanks in advance Ravi Verelly for the script.
ak jalanin di PSP kok gak jalan ya..?
Well. I don’t think it works fine with IE 7.
Did you test?
src: http://support.microsoft.com/kb/251133/en-us/
Regards.
for Dhunk and Jack :
I’ll try with PSP using IE7 it work, but it has some limitations.
but I forgot whats the limitations.
Maybe You could find with some experiment and some tricky
Thank you for your website ![]()
I made with photoshop backgrounds for myspace or youtube and whatever
my backgrounds:http://tinyurl.com/6rbxmr
have a good day and thank you again!
hi
Excellent Job done and Thank You For the code
Most Comprehensive code for printing and other tasks,but didn’t find the page setup one?
Can You help?
Thank you very much
Hope, any good thing will go to you.
a lot of thanks.
the “javascript call print preview” code is not working !!
Confirmed: doesn’t work with Firefox 3 / IE7
Indeed, it does not work.
Thanks mate… works with IE
for some reason when I copied the code from here it didn’t work ((
But when I modified it slightly it worked just fine. I am using IE7 and didn’t try it on anything else. I think the problem was with wrong quotes originally. Sorry, if this repeatation is inappropriate, but I thought it might help someone.
function printpr()
{
var OLECMDID = 7;
/* OLECMDID values:
* 6 – print
* 7 – print preview
* 1 – open window
* 4 – Save As
*/
var PROMPT = 1; // 2 DONTPROMPTUSER
var WebBrowser = ”;
document.body.insertAdjacentHTML(‘beforeEnd’, WebBrowser);
WebBrowser1.ExecWB(OLECMDID, PROMPT);
WebBrowser1.outerHTML = “”;
}
Oops, it didn’t work right the first time and there is no option to change what I posted. So here is another try
!
!
function printpr()
{
var OLECMDID = 7;
/* OLECMDID values:
* 6 – print
* 7 – print preview
* 1 – open window
* 4 – Save As
*/
var PROMPT = 1; // 2 DONTPROMPTUSER
var WebBrowser = ”;
document.body.insertAdjacentHTML(‘beforeEnd’, WebBrowser);
WebBrowser1.ExecWB(OLECMDID, PROMPT);
WebBrowser1.outerHTML = “”;
}
!
!
Hi,
Can you pls send me the full code as email so that it would be of great use!
Thanks
Well… seems I cannot post it right here. Tag signs are screwed up. You can delete these comments, there’s no use of them like this.
It works fine in IE .
if it is not working-mostly because your IE already disable ActiveXobject. Please enable it.
Firefox is not support for this code.
Firefox browser have its own print preview function -You can call the nsIWebBrowserPrint::PrintPreview() method.
Or simple way to do is using popup window to do the print preview job.more easier ~ ^_^
13 April 2007 at 1:29 pm
Note about Scripting Support for Web Page Printing from microsoft
WebBrowser is known to support OLECMDID_PRINT(6,1) and OLECMDID_PAGESETUP(8) printing related commands
The trick is to create a temporary WebBrowser object with DHTML and invoke ExecWB(6, 1) on it to print the page.
ExecWB(6, 1) could fail if a user selected the Cancel button on the print dialog
for detail article click :
http://msdn2.microsoft.com/en-us/library/ms976105.aspx