Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    rhs
    rhs is offline
    New Coder
    Join Date
    Jun 2003
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts

    "print this page link"

    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

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You do not need any script. Browsers have this functionality built-in.
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #3
    rhs
    rhs is offline
    New Coder
    Join Date
    Jun 2003
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Vladdy,

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

    RHS

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    <a href="javascript:document.print()">Print this page</a>

  • #5
    rhs
    rhs is offline
    New Coder
    Join Date
    Jun 2003
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #6
    Regular Coder
    Join Date
    Jun 2003
    Location
    Spokane, WA
    Posts
    512
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 .

    -Ben

  • #7
    rhs
    rhs is offline
    New Coder
    Join Date
    Jun 2003
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


    RHS

  • #8
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    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

  • #9
    Regular Coder
    Join Date
    Jun 2003
    Location
    Spokane, WA
    Posts
    512
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh, ya...no problem!
    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.

    -Ben

  • #10
    rhs
    rhs is offline
    New Coder
    Join Date
    Jun 2003
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Ben,

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

    could you please help

    RHS

  • #11
    Senior Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    1,137
    Thanks
    0
    Thanked 0 Times in 0 Posts
    use #null to avoid going to the top of the page when the link is clicked.

    scroots
    Spammers next time you spam me consider the implications:
    (1) that you will be persuaded by me(in a legitimate mannor)
    (2)It is worthless to you, when i have finished

  • #12
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Moving thread to JS programming...
    OracleGuy

  • #13
    Regular Coder
    Join Date
    Jun 2003
    Location
    Spokane, WA
    Posts
    512
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #14
    rhs
    rhs is offline
    New Coder
    Join Date
    Jun 2003
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #15
    New to the CF scene
    Join Date
    Aug 2003
    Location
    Dallas
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can you make it print "landscape"?

    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 !!


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •