Forum Moderators: open

Message Too Old, No Replies

Printing without header or footer

javascript using ExecWB to print a page.

         

Jitsua

7:39 pm on Jun 27, 2005 (gmt 0)



Sorry if this is a resolved subject, I was searching google looking for a way to print a page without the default header and footer. Google pointed me to a thread on this site [webmasterworld.com...] but the question was not resolved. Well I happend to come across something thats working for me, so I thought I would share it for any that are still wondering.

<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 = 7; // 2 DONTPROMPTUSER
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);

// the third argument of the following ExecWB call
// is supposed be a safearray containing extra
// information including a header and footer,
// I threw a null in there and it seems to work.

WebBrowser1.ExecWB(OLECMDID, PROMPT, null); WebBrowser1.outerHTML = "";
}
</script>
</head>
<body>
<form>
<input type='button' value="Print Preview" onclick="printpr();">
</form>
</body>
</html>

Farix

9:30 pm on Jun 27, 2005 (gmt 0)

10+ Year Member



A print specific stylesheet often works better.