Results 1 to 3 of 3

Thread: javascript and print friendly version

  1. #1
    Join Date
    Sep 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default javascript and print friendly version

    Could someone please help me with this. I want to have a “Print Friendly Version” on my web site, when user click on the button, a new window will pop up so user can preview what will be printed before they decide to print it or not. Here is the javascript code:

    <script type="text/javascript">
    if(self.opener){
    window.onload=opener.appSty;
    }
    function winPrint(){
    newWin=window.open('index.htm','','height=800,width=800,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable =yes');
    }
    function appSty(){
    var win_style=newWin.document.createElement('link');
    win_style.href="../Main/print.css";
    win_style.rel="stylesheet";
    win_style.type="text/css";
    newWin.document.getElementsByTagName('head')[0].appendChild(win_style);
    newWin.focus();
    }
    </script>
    And it called here:

    <img src="print_button.gif" onClick="winPrint();">

    The problem is I don’t want to type a file name for window.open in every single page. Does anyone has a better way to do this? Thank you in advance.

  2. #2
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by newtojavascript
    I want to have a “Print Friendly Version” on my web site, when user click on the button, a new window will pop up so user can preview what will be printed before they decide to print it or not.
    Just include a print style sheet properly. The user can then use the print preview function of their browser, which will also show page breaks, footers, and other features that yours wouldn't.

    HTML Code:
    <link rel="stylesheet" type="text/css" href="..." media="print">
    Mike

  3. #3
    Join Date
    Sep 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Mike,

    Thanks for your response, I personnally prefer your way, but my colleague want the other way.

Bookmarks

Posting Permissions

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