Removing headers, footers and margins when printing (IE)
** As many other have suggested Print Templates are a better way to achive this. I hope to convert our application to use them, at which pooint I will replace this article.**
Internet Explorer, by default, will always ouput headers, footers and margins when printing a web page. This can causes no end of issues when developing web applications that need to print reports, invoices or letters. This can be overcome with some simple script.
The following code shows how to read and modify the registry. The site does need to be a "trusted site" and there is a warning when it happens but this doesn't need to be done more than once.
function test()
{
try
{
// string to the regkey we want to modify
cKeyPath = "HKCU\\Software\\Microsoft\\" +
"Internet Explorer\\PageSetup";
// create an instance of the WScript.Shell object
var wsShell = new ActiveXObject("WScript.Shell");
// read from the reg
alert(wsShell.RegRead( cKeyPath + "\\margin_bottom"));
// write to the reg
wsShell.RegWrite(cKeyPath + "\\margin_bottom", "0" );
// read again
alert(wsShell.RegRead( cKeyPath + \\margin_bottom"));
}
catch(e)
{
// If the user has not added the site to the trusted list
// or they clicked cancel you will reach here.
alert( "Please read the faq about printing" )
}
}
I am not going to add an example to this post as it's very obtrusive code. And I highly reccomend against using it on applications that aren't on intranets.
This script only works in IE