Forum Moderators: open

Message Too Old, No Replies

Printing a different page

Printing a different page

         

themoron

2:34 pm on May 22, 2003 (gmt 0)



I assume someone knows the answer.

I am trying to create a text link on my website that allows the user to print a 'printer friendly' version of the page.

I have found the code
a href="javascript:window.print">Print this page</a>

but it only prints the current page.

Is there a way to target another page (the preformatted version) and print it without opening it first?

BlobFisk

2:39 pm on May 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't think so. Javascript can only access pages that are open (and related). You would need to open the new page first and then print it.

buckworks

3:16 pm on May 22, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Another approach would be to stay with just one page, but set up a printer-friendly stylesheet to be used only when the page is printed. Then you could hide ads, nav menus, etc. or show company info on the printout - whatever variations you want.

Something to watch out for: if you have any reverse color effects -- light print on a coloured background for a pullquote, for example -- if the person has their printer set to ignore background colours (to save ink) the light print might be unreadable. CSS can let you change what colour things will be if the page is printed, to make sure everything is readable.

Site maintenance is easier when you use CSS to make existing pages printer-friendly, because you don't have to create or maintain any extra pages just for printing.

themoron

3:23 pm on May 22, 2003 (gmt 0)



Thanks Guys,

I think I will just have to opt for the open a new window, and have a print link on that page. I am too lazy to create a style sheet at the moment. It is something to incorporate in the future though.

Thanks again

themoron :@)

Tripz

6:23 pm on May 22, 2003 (gmt 0)


There is a way by loading into a hidden frame.

<frameset rows="100%,*">
<frame src="controlpage.html">
<frame src="printpage.html">
</frameset>

Put this in your control page:

<script language="JavaScript">
<!--
if (window.print)document.write('<form><input type="button" value="Print" onClick="parent.frames[1].focus();parent.frames[1].print()"><\/form>');
//-->
</script>

Hope this helps! ;)

themoron

9:16 pm on May 22, 2003 (gmt 0)



Great thanks!

I think that might just work

themoron :@)

BlobFisk

9:51 pm on May 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, Tripz!

Nice workaround! Although, the page (in the hidden frame) would need to be quite lightweight so as not to have a major impact on the page size and download time.