Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

JS cross browser print

11:50 pm on Jan 24, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 25, 2000
votes: 0

Is there a cross browser way to print?
12:08 am on Jan 25, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:May 26, 2000
votes: 0

I think it depends on how complete you want the compatibility to be. I'd guess that there are OS anomalies to deal with, as well as browser versions.

Here's a link for javascript printing [developer.irt.org] from NN4+ and IE5+. It also includes vbscript for IE3 and IE4.

1:53 pm on Jan 28, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 10, 2001
votes: 0

I just thought I'd add this here for reference and interest. You can also deal with IE4 using javascript with the following code (IE only), this is interesting as you can also invoke other windows dialogs like print preview, page setup, save page as etc directly from your page using javascript. Copy the following code into your editor and preview in IE4+... I'm sure most of you can work out what's going on in the source.


function printpr(OLECMDID)
//var OLECMDID = 10;
/* OLECMDID values:
* 6 - print
* 7 - print preview
* 8 - page setup (for printing)
* 1 - open window
* 4 - Save As
* 10 - properties
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
WebBrowser1.outerHTML = "";
<form name="form">
<select name="olecmdid">
<option value="6">Print
<option value="7">Print Preview
<option value="8">Page Setup for printing
<option value="1">Open File
<option value="4">Save this web page as....
<option value="10">View the properties of this file
<input type="Button" value="Go" onclick="printpr(document.form.olecmdid.value);">

You can get a full list of OLECMDID values from here [msdn.microsoft.com] though not all will work depending on the available functions in your browser.