Javascript and php print ready

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
nhan
Forum Commoner
Posts: 95
Joined: Sun Feb 27, 2005 8:26 pm
Contact:

Javascript and php print ready

Post by nhan »

i have here a code but i cant seem to make this work... can anyone help?
thanks!

it gives me an error "access denied" i dont know where this access denied is...

thanks!

Code: Select all

<script type=&quote;text/javascript&quote;>
<!-- 
var gAutoPrint = true; // Flag for whether or not 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(&quote;head&quote;); 
if (headTags.length > 0) 
html += headTags&#1111;0].innerHTML; 
} 

html += '\n</HE' + 'AD>\n<BODY>\n'; 

var printReadyElem = document.getElementById(&quote;printReady&quote;); 

if (printReadyElem != null) 
{ 
html += printReadyElem.innerHTML; 
} 
else 
{ 
alert(&quote;Could not find the printReady section in the HTML&quote;); 
return; 
} 

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

var printWin = window.open(&quote;&quote;,&quote;printSpecial&quote;); 
printWin.document.open(); 
printWin.document.write(html); 
printWin.document.close(); 
if (gAutoPrint) 
printWin.print(); 
} 
else 
{ 
alert(&quote;Sorry, the print ready feature is only available in modern browsers.&quote;); 
} 
} 
//--> 
  </SCRIPT>
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

it probably has to do with the call to do the printing as alot of people and browsers wont allow auto printing like that.
User avatar
nhan
Forum Commoner
Posts: 95
Joined: Sun Feb 27, 2005 8:26 pm
Contact:

Post by nhan »

tried it using asp and it seems to work fine, but in php errors occur....
is there any other work around??

thanks!
Post Reply