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.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Feb 2005
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    print preview in new window

    I am trying to do a print preview in a new window. I want only the main content area to come up in the new window. I have a script that will grab everything inside a div and throw it in a new window, but it will not transfer anything inside any other tags inside the div.

    This is my function that I call...

    <script LANGUAGE="JavaScript">
    function displayHTML() {
    var inf = document.getElementById('printarea').innerHTML;
    win = window.open("print.htm", 'popup', 'toolbar = no, status = no');
    win.document.write(inf + "<br /><a href='javascriptrint()'>print</a>");
    win.document.close();
    }
    </script>

    What doesn't work though is if I have
    <div id="printarea">adf
    <table><tr><td>content here</td></tr></table>
    </div>

    With this what I get in the new window is the "adf" not the table.

  • #2
    New Coder
    Join Date
    Mar 2005
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Strange... the following worked as expected for me....?

    Code:
    <html>
    <head>
    <script>
    function displayHTML() {
    var inf = document.getElementById('printarea').innerHTML;
    win = window.open("print.htm", 'popup', 'toolbar = no, status = no');
    win.document.write(inf + "<br /><a href='javascriptrint()'>print</a>");
    win.document.close();
    }
    
    </script>
    </head>
    <body>
    <button onclick="displayHTML()" >print preview</button>
    <div id="printarea">adf
    <table><tr><td>contents of table here</td></tr></table>
    </div>
    
    </body>
    </html>
    "It doesn't matter if I'm optomistic or not, nothing ever works out for me."

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,074
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Why did you start a new thread when you already posted this? Have you considered my suggestion in that thread?
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #4
    New Coder
    Join Date
    Feb 2005
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I did look at your suggestion and that would be the ideal solution. This is the situation though....I'm inheriting a poorly coded site and the client doesn't want to do a full recode. They are also insistant that there be a preview, that is not the standard print preview. I'm sure you understand when clients get something set in their mind and they won't let it go.


  •  

    Posting Permissions

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