...

View Full Version : "print this page link"



rhs
07-11-2003, 03:08 PM
Hi everyone,

does anyone know of a javascript or php script that will allow clicking on a link to print the current html document in the browser. the link could be text or a small image.


Thanks

RHS

Vladdy
07-11-2003, 03:12 PM
You do not need any script. Browsers have this functionality built-in.

rhs
07-11-2003, 03:15 PM
Thanks Vladdy,

what is a browser by the way? never seen one.
and what is a website , any clue?

RHS

Nightfire
07-11-2003, 03:34 PM
<a href="javascript:document.print()">Print this page</a>

rhs
07-11-2003, 03:46 PM
Thanks NightFire,

I am not conversant with javascript ( cannot write my own codes) . My client wants such a link on his page.

Good to see there are still helpful people like you around.

And there are others who just cannot stand others honesty.
I knew some people would think this is a silly question.

Thanks a ton

:)
RHS

Ben@WEBProp
07-11-2003, 04:43 PM
Not to be a tool or anything, but I have recently learned that
<a href="javascript:document.print()">Print this page</a> has been depreciated.

The code you REALLY want is
<a href="#" onclick="javascript:window.print();return false">
This makes it so that when the print command is clicked, the screen doesn't reposition itself.

I have learned that there is SO many things that you can do with this code! Like let's say that you don't want the words "Print This Page to appear on the printed document. Just slap this code in the <head> section of your page:

<style type="text/css" media="print">
.dontprintme { display: none; }
</style>

And then add on class="dontprintme" after ;return false.
So if you did add all that stuff, your end print code will be
<a href="#" onclick="javascript:window.print();return false" class="dontprintme">

In addition to
<style type="text/css" media="print">
.dontprintme { display: none; }
</style>
Pasted into the head of your document. It's that easy. The other way will work, but this is more efficient:thumbsup: .

-Ben

rhs
07-11-2003, 05:08 PM
Thanks Ben
and Nightfire,

there are really so many helpful guys.
Forums are meant to exchange our knowledge and help others, aren't they

Cheers

:thumbsup:
RHS

Nightfire
07-11-2003, 05:27 PM
Ta Ben for the latest standard :) Been out of js for a few years, so not had the chance to catch up with it all yet :)

Ben@WEBProp
07-11-2003, 05:35 PM
Oh, ya...no problem!:o
I just ran into those problems very recently on my page and I had no clue where to even start. I'm a newb at javascript, but I thought that I would share the limited knowledge that I do have. :D

-Ben

rhs
07-12-2003, 11:53 AM
Hi Ben,

Your code is great , I did exactly as you said, it does everything but print the page!

could you please help

RHS

scroots
07-12-2003, 02:31 PM
use #null to avoid going to the top of the page when the link is clicked.

scroots

oracleguy
07-12-2003, 07:51 PM
Moving thread to JS programming...

Ben@WEBProp
07-14-2003, 04:21 PM
rhs-
What browser are you using? IF it is fairly recent IE, then it should work...and I think I know what is going wrong...

The css part that declares
<style type="text/css" media="print">
.dontprintme { display: none; }
</style>
tells the browser that whatever has the attribute class="dontprintme" should not be printed...so the only thing i could think of is that you didn't anchor your <a ...>, so just do

<a href="#" onclick="javascript:window.print();return false" class="dontprintme">Print This Page</a>

If this were translated into English, this would mean: Here is a link, but it doesnt go anywhere. Instead when you click me, I want you to print the window, but not return to the top of the page. I also dont want you to print the words that are after the > symbol. However, print everything after the </a>.

Lemme know if that helps!

-Ben

rhs
07-14-2003, 05:46 PM
Hi,

I tested it on IE 5.2.2 on the Mac that's a fairy recent browser for the mac platform (IE5.3 is the latest)

Will check the codes again and let you know.

thanks

RHS

claydaddy
08-15-2003, 12:10 AM
Most websites are laid out horizontally in a roughly 3:4 ratio, yet our printers are by default set to print Portrait style.... That doesn't work too well... So I was wondering if there is a way to make....

<a href="#" onclick="javascript:window.print();return false">

print the page in Landscape format, without the end user having to go change anything in their printer properties.

Any help would be appreciated.

Thanks in advance !!

Choopernickel
08-15-2003, 01:53 PM
Unfortunately, not seamlessly.

This is due to the lack of support for the @page (media:print specific) selector in CSS parsers in every major browser (at my last check). Were that supported, it would be the preferred way to instruct the printer.

Otherwise, for Windows and I.E. there is ActiveX, with which you can use a system object to move through the menus and popups for the user, to select the landscape option. This can be highly unsecure, and usually not trusted outside an intranet.

If you want specific help with the ActiveX object, PM me and I'll get back to you.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum