HTML Help Forum HTML Help
Please Search for the answer to your question before asking it! Thanks.
 

Javascript Print button, prints before text has loaded
Post a Reply to this Topic Ask a New Question
Click here to go to the original topic
       HTML Help Forum -> Javascript
View previous topic :: View next topic  
Author Message
Methicone



Joined: 28 Oct 2008
Posts: 3

Posted: Wed Dec 10, 2008 8:15 am     Javascript Print button, prints before text has loaded  

Hi,

I have some javascript code that i found on the web, which is used to print a specific area of text. Its made up of three steps:

Step 1:
This code goes in the <head>

<script language="JavaScript">
var gAutoPrint = true; // Tells whether to automatically call the print function

function printSpecial()
{
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 printReadyElem = document.getElementById("printReady");

if (printReadyElem != null)
{
html += printReadyElem.innerHTML;
}
else
{
alert("Could not find the printReady function");
return;
}

html += '\n</BO>\n</HT>';

var printWin = window.open("","printSpecial");
printWin.document.open();
printWin.document.write(html);
printWin.document.close();
if (gAutoPrint)
printWin.print();
}
else
{
alert("The print ready feature is only available if you are using an browser. Please update your browswer.");
}
}
</script>

Step 2:
This goes around the text you want to print

<div id="printReady">
</div>

And step 3:
The print button

<a href="javascript:void(printSpecial())">Print this Page</a>

The page i want to print text off of is a dynamic page, but for some reason if i use this script it prints a blank page and comes up with the error, "Page cannot be changed whilst printing" but then continues to load the text correctly after the blank page has printed. I then have to manual go File -> Print.

Is there a way to deley the automatic print function?
 
 
DARFUR
HOSTING / DESIGN
MAKE MONEY

       HTML Help Forum -> Javascript
Page 1 of 1


Powered by phpBB Search Engine Indexer
Powered by phpBB 2.0.19 © 2001, 2002 phpBB Group