print using frames

P

prophet

how do I create a print button that is on my index page that prints my
target page (and only the target page)

I tried
<INPUT onclick=window.print(); type=button value="Print This Page"
style="font-size: 10px; float:right">

But it prints the index page.

Thank you.
 
O

Oliven

Hello,

Here is a solution:

Code for your index page:
--------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<h2>Index page</h2>
<script>
function printMyOtherPage() {
// It is forbidden to change the iframe src so we submit a form into
it
// with the desired page as the action.
// We also add a parameter PRINT_ME so that the page can detect that
it
// has to print herself.
document.PRINTER.action = document.PRINTER.PAGE_TO_PRINT.value;
document.PRINTER.submit();
}
</script>
<form name="PRINTER" target="printedFrame" action="">
<input type="hidden" name="PRINT_ME">
The page you want to print <input name="PAGE_TO_PRINT" type="text"
value="page1.htm">
<input type="button" onClick="printMyOtherPage();" value="Print it">
</form>
<iframe name="printedFrame" src="dummy.htm"
style="visibility:hidden"></iframe>
</body>
</html>

Code of the page you want to print from the index page, ex apge1.htm
(you just need to copy the Onload attribute in the desired pages):
------------------------------------------------------------------------------------------------------------------------------------------------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body onLoad="if (location.href.indexOf('PRINT_ME') != -1)
window.print();">
page1
</body>
</html>

Hopes it will help you.

Olivier
 
R

Randy Webb

prophet said the following on 1/25/2007 11:18 PM:
how do I create a print button that is on my index page that prints my
target page (and only the target page)

I tried
<INPUT onclick=window.print(); type=button value="Print This Page"
style="font-size: 10px; float:right">

But it prints the index page.

You could try reading the group FAQ, specifically section 4.11
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top