By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,740 Members | 844 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,740 IT Pros & Developers. It's quick & easy.

print using frames

P: n/a
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.
Jan 26 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a

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

On Jan 26, 5:18 am, "prophet" <M_Mo...@hotmail.comwrote:
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.
Jan 26 '07 #2

P: n/a
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

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 27 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.