This is a simple page to demonstrate some of the ideas, problems and solutions discussed on my page about frames.

This page is to demonstrate various ways to print a framed page, or at least to make it "print ready".

Some of the easiest ways are to use the techniques discussed in how to break out of frames. you can always change the link or button text to read "Printable version" or whatever you like.

You could open the page in a new browser window. If you're using an HTML link you just need to use the target=_blank attribute. For example to open this page in a new browser window, the code would be...

<p align="left"><font size="4" color="#0000FF"><a href="frmmainprn.htm" target=_blank>Printable version (in new window)</a></font></p>

which gives...

Printable version (in new window)

To do something similar in JavaScript, put this in the HEAD section of your page...

<SCRIPT LANGUAGE="JAVASCRIPT">
<!-- Hide from old browsers
function newwin(){
window.open(document.location.href);
}
// Stop hiding from old browsers -->
</SCRIPT>

Then in the BODY of your page put...

<input type="button" onclick="newwin()" value="Printable version">

Which gives...

You may like to give your visitor the option of simply clicking on a button to print the page or frame the button is on. If this is the case then add this to the HEAD section of the page...

<SCRIPT LANGUAGE="JAVASCRIPT">
<!-- Hide from old browsers
function printfrm(){
window.print()
}
// Stop hiding from old browsers -->
</SCRIPT>

Then in the BODY of your page put...

<input type="button" onclick="printfrm()" value="Print this page">

Which gives...

Opera 7.54 will still continue to print out the entire frame set, but the other browsers behave as they should.

An alternative is to use the following code in the head section of your page...

<SCRIPT LANGUAGE="JAVASCRIPT">
<!-- Hide from old browsers
function frmprint(frmname){
parent[frmname].focus();
parent[frmname].print();
}
// Stop hiding from old browsers -->
</SCRIPT>

Then in the BODY of your page put...

<input type="button" onclick="frmprint('xxxxxxxx')" value="Print main frame">

Replace xxxxxxxx with the name of the frame that you'd like printed. The nice thing about this piece of code is that it will print any displayed frame from any other. This means you can, for example, put the button in the navigation frame, but by replacing xxxxxxxx with the name of the main frame, you can print the main frame content.

In the example below, xxxxxxxx has been replaced with the main frame name of this page which is mainfrm. The code is now...

<input type="button" onclick="frmprint('mainfrm')" value="Print main frame">

To show that this works properly, the next button uses the code...

<input type="button" onclick="frmprint('menufrm')" value="Print menu frame">

I was hoping that the above code would sort out the problem that Opera 7.54 has with printing framed pages, but, unfortunately, it didn't. Opera 7.54 continued to print out the entire contents of the window. The code works exactly as it should for the other browsers.

This page created 29th October 2004, last modified 31st October 2004


GoStats stats counter