Page 1 of 1

Javascript and php print ready

Posted: Sat May 28, 2005 9:27 am
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>

Posted: Sat May 28, 2005 10:00 am
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.

Posted: Sat May 28, 2005 10:19 am
by nhan
tried it using asp and it seems to work fine, but in php errors occur....
is there any other work around??

thanks!