Connecting Tech Pros Worldwide Forums | Help | Site Map

print using frames

prophet
Guest
 
Posts: n/a
#1: Jan 26 '07
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.



Oliven
Guest
 
Posts: n/a
#2: Jan 26 '07

re: print using frames



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:
Quote:
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.
Randy Webb
Guest
 
Posts: n/a
#3: Jan 27 '07

re: print using frames


prophet said the following on 1/25/2007 11:18 PM:
Quote:
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/
Closed Thread