Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q993 How can I print four separate documents with a single button click?

You are here: irt.org | FAQ | JavaScript | Print | Q993 [ previous next ]

Only by loading a framset with all four pages loaded - with the onLoad event handler in the frameset using the window print method to print each frame:

<form>
<input type="button" onClick="if (window.print) location.href='printframeset.htm'">
</form>

And then in printframeset.htm:

<html>
<head>
<script language="JavaScript"><!--
function printAll() {
    for (var i=0;i<frames.length;i++)
        if (window.print)
            frames[i].print();
}
//--></script>
</head>

<frameset onLoad="printAll()" rows="*,*,*">
<frame src="apage.htm">
<frame src="anotherpage.htm">
<frame src="yetanotherpage.htm">
</frameset>
</html>

The previous script has been reported not to work on some platforms (it works perfectly on Netscape Navigator 4.7 on Linux). I assume on some platforms only one print dialogue box at a time can be opened. It might be possible to overcome this with a setTimout, but its going to be difficult to know when to start another one. A set delay of, say, 5 seconds might be too short if the user doesn't hit the print button. Anyway try:

<html>
<head>
<script language="JavaScript"><!--
function printAll() {
    for (var i=0;i<frames.length;i++)
        if (window.print)
            setTimeout('frames[' + i + '].print()',5000 * i);
}
//--></script>
</head>

<frameset onLoad="printAll()" rows="*,*,*">
<frame src="apage.htm">
<frame src="anotherpage.htm">
<frame src="yetanotherpage.htm">
</frameset>
</html>

Feedback on 'Q993 How can I print four separate documents with a single button click?'

©2018 Martin Webb