Hi all,

I want to print a page from another page. I have a master page with links to other page. When I click "print," it should print the another page.
The function window.print() is printing only the active page. So on click print i am opening a new window.

In the onload event of the target page i have used
<body onload="window.focus();window.print();window.close ();">

Eventhough it's working, at the same time the window is also popping up behind the printer set up screen. when i click print or cancel the window gets closed automatically.
i don't want the window to pop up. Do suggest me if there is any other alternative way..

Thanks for your help.

Member Avatar for diafol

I think the page has to be open before you print it - but you can use an invisible iframe (cheat):

<script type="text/javascript">
function printPage(iFid){
iFid.focus();
iFid.print();
}
</script>
<style>
#iframe1{
visibility:hidden;
}
</style>
</head>
<body>
<iframe name="iframe1" id="iframe1" width="1" height="1" src="index.php"></iframe>
<a value="print page" href="javascript:printPage(iframe1);">print page</a>
</body>
</html>

I got this idea from here and just tinkered with it.

That's good idea. It worked for me. Thanku for your time and for detailed response.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.