Print Button, HTML

Associate
Joined
16 Mar 2004
Posts
1,889
Location
Oxford
I'm trying to add a print button to a web page that only prints one section of the page. The section that needs printing is an inline frame (I1) however I can only get it to print out the whole page. Here is the code I have so far:

Code:
<form><input type="button" value="Print"
onclick="window.print();return false;" /></form>

What do I need to change to get it to work? Any help would be appreciated.
 
Associate
Joined
9 Jun 2006
Posts
954
Location
Manchester
This one works for me:

Code:
<script language="javascript">
var message = "Print";
function printit() {
window.print();  
}
document.write("<form><input type=button "
+"value=\""+message+"\" onClick=\"printit()\"></form>");
</script>
 
Associate
OP
Joined
16 Mar 2004
Posts
1,889
Location
Oxford
I've tried that and for some reason it doesn't, I've just thought of a few things I have not mentioned;

The print button is to be displayed in the main area of the page, the inline frame is within the main page and displays a text file which is what I want to be able to print on its own.

The inline frame is called I1.

Hope this makes sense, I just have no idea how to do this.
 
Associate
Joined
28 Jun 2005
Posts
895
I haven't fiddled with this stuff for a while but I think you need to give the IFRAME focus first.
Code:
<script>
function printIFrame()
{
	parent.I1.focus();
	parent.I1.print();
}
</script>

<form><input type="button" value="Print" onclick="printIFrame" /></form>
 
Associate
OP
Joined
16 Mar 2004
Posts
1,889
Location
Oxford
Thanks, it works, I wondered about giving the Iframe focus as its what I had read about it when googling on the topic, however I couldn't work out what code was required to do this.
 
Back
Top Bottom