Question

At cbjsonline.com, I'm trying to have a pdf in an iframe print automatically with javascript.

Currently, my code is - (connected to the onclick of the link that opens the iframe) - document.getElementById('fancy_frame').onload = setTimeout('window.print()',2500);

Any suggestions? This method only works in safari.

Was it helpful?

Solution

Try passing a function pointer to setTimeout, instead of an expression that gets eval'd.

document.getElementById('fancy_frame').onload = setTimeout( printWindow, 2500 );

// implemented in the HTML that is loaded in 'fancy_frame'
function printWindow()
{
    window.print();
}

OTHER TIPS

OK, I decided to let the user print the page. I think iFrames with PDFs are too variable trying to print with javascript. If anyone wants to try this, this is what I'd recommend. Use the jquery load, which checks for assets, not just loading, not the onload handeler, because the delay for adobe reader varies greatly across computers. Also, try naming and focusing the iframe before printing (by name, so iframe.print(), instead of window.print()), that way it won't try to print the page your currently on. It might be a better idea just to use the scribd ipaper viewer for this application.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top