You can use following code lines to print a web page:
In some case, you want to hide the print dialog
, print the webpage with default installed printer. In my way, i develop a small program as utility, it runs in background, searching the print dialog and close it automatically by pressing OK button?! I have tested on some local machine. It works fine! :)
Download: HidePrintDlg.exe
Run it and click "Print this page" button again. Does it work fine? :)
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
<script language="javascript">
function PrintPage(){
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 = "";
}
}
</script>
</head>
<body>
<input type="button" onclick="PrintPage();" value="Print this page" />
</body>
</html>
You can copy above code lines into a .html page, open it in a browser, click on "Print this page" button to open print dialog, choose a printer and click OK button to print the webpage.<head>
<title>Untitled Page</title>
<script language="javascript">
function PrintPage(){
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 = "";
}
}
</script>
</head>
<body>
<input type="button" onclick="PrintPage();" value="Print this page" />
</body>
</html>
In some case, you want to hide the print dialog
, print the webpage with default installed printer. In my way, i develop a small program as utility, it runs in background, searching the print dialog and close it automatically by pressing OK button?! I have tested on some local machine. It works fine! :)
Download: HidePrintDlg.exe
Run it and click "Print this page" button again. Does it work fine? :)
Comments
Please get the source code (C4W) here