Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: JavaScript
Expertise: Advanced
Jul 28, 2003

Print an HTML Page Without Displaying the Print Dialog Box

The following piece of code is a sample example that can print a HTML page without showing the print-popup dialog box. NOTE: It is restricted with IE 5.5 SP2 onwards.

Example:


<script LANGUAGE="JavaScript">

// The code below does work  and is tested with IE 5.5 SP2.
function printitWithoutDialog()
{
		if ((navigator.appName == "Netscape"))
		{
			window.print() ;
		}
		else
		{
			var WebBrowser = 
'<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0
CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2">
</OBJECT>';
	document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
	WebBrowser1.ExecWB(6, -1);
	WebBrowser1.outerHTML = ;
		}
}//printit


</script>

<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>

<body>
<a href="javascript:printitWithoutDialog() ">print this page</a>
</body>

</html>
Supal Chowdhury
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date