Jump to content

print part of page script help


wagga2650

Recommended Posts

I have this script that when you place anything in div tags and give the correct ID it will print only that data. I ususlly works fine but since upgrading Firefox to 3.6.3 it only prints a blank page instead of the data on it.

 

 

Instructions to use:

 

place a div on your page and give it an id="printMe then add some content between the div and then finally add the head and body code and try and print it. Sometimes on Firefox it works for me and others it fails, It works fine in IE.

 

Thanks in advance if anyone can sofrt it out for me.

 

here is the script

 

------Head code below----

 

<script language="JavaScript">
var gAutoPrint = true; // Tells whether to automatically call the print function
function printMe()
{
if (document.getElementById != null)
{
var html = '<HTML>\n<HEAD>\n';
if (document.getElementsByTagName != null)
{
var headTags = document.getElementsByTagName("head");
if (headTags.length > 0)
html += headTags[0].innerHTML;
}
html += '\n</HE>\n<BODY>\n';
var printareaElem = document.getElementById("printarea");
if (printareaElem != null)
{
html += printareaElem.innerHTML;
}
else
{
alert("OOPS! could not find the printarea function");
return;
}
html += '\n</BO>\n</HT>';
var printWin = window.open("","printMe");
printWin.document.open();
printWin.document.write(html);
printWin.document.close();
if (gAutoPrint)
printWin.print();
}
else
{
alert("The print ready feature is only available in modern browsers. Please update your browswer.");
}
}
</script>

 

 

---body code for button below

 

<form id="printMe" name="printMe"> 
<input type="image" name="print" onClick="printMe()" src="images/printme.jpg">
</form>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.