Print button for another page?

G

Guest

Is it possible for a "PRINT" button on one page to automatically print a
different page when clicked? I created the "PRINT" with the following code
and was thinking if "window,print();return false" could be tweaked by
substituting another page for "window".

Thanks
6West
 
J

Jon Spivey

Hi,
Can't be done. You have to display a page before you can print it. Best you
could do is open the page in a new window and set it to print onload
 
T

Trevor L.

Jon,
Re your post to "sixwest"

I have wondered myself about printing one page from another.

I have cobbled together this code from various sources including this
newsgroup - I think Murray was one of them.

function print_page()
{
if (window.print)
{ parent.index_main.focus(); top.frames['index_main'].print() }
else
alert("Select \"Print\" from the menu")
}

I call this function from a frame (named sidebar) to print another frame
(named index_main). It works fine.

Can I ask your expert advice.
1. Does this work because I am printing another *frame* rather than another
*page* ?
2. Is it possible to adapt this approach to print another page?

I can see the idea behind your suggestion
Open the other page in a new window
Print it onload

If one could then automatically close it, I assume it would do what is
wanted (albiet with a bit of trickery).
 
J

Jon Spivey

Hi Trev,
Yes - we can address any frame within a frameset from any other frame but as
printing happens client side the page has to be in a browser window before
it can be printed. My way would be the closest to the functionality the guy
wants. With the understanding that it only works in IE might be worth trying
<script type="text/javascript">
window.onafterprint=self.close();
</script>
To close the page after it's printed. We could also throw focus back to the
main window then the window to be printed is opened, this should make the
whole thing look seamless to the user.

--
Cheers,
Jon
Microsoft MVP

Trevor L. said:
Jon,
Re your post to "sixwest"

I have wondered myself about printing one page from another.

I have cobbled together this code from various sources including this
newsgroup - I think Murray was one of them.

function print_page()
{
if (window.print)
{ parent.index_main.focus(); top.frames['index_main'].print() }
else
alert("Select \"Print\" from the menu")
}

I call this function from a frame (named sidebar) to print another frame
(named index_main). It works fine.

Can I ask your expert advice.
1. Does this work because I am printing another *frame* rather than
another *page* ?
2. Is it possible to adapt this approach to print another page?

I can see the idea behind your suggestion
Open the other page in a new window
Print it onload

If one could then automatically close it, I assume it would do what is
wanted (albiet with a bit of trickery).
--
Cheers,
Trevor L.
Website: http://tandcl.homemail.com.au
(see website to send email)

Jon said:
Hi,
Can't be done. You have to display a page before you can print it.
Best you could do is open the page in a new window and set it to
print onload
 

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

Top