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

    print preview window

    I would like to create a print preview window that will display only the main content of the page that a person would really want to print. I found a script that didn't do that, but that I was able to adapt, somewhat. It doesn't fully work though and I can't get it any better. Here is what I have...

    <html>
    <head>
    <title></title>
    <script LANGUAGE="JavaScript">
    function displayHTML(printContent) {
    var inf = printContent;
    win = window.open("print.htm", 'popup', 'toolbar = no, status = no');
    win.document.write(inf);
    }
    </script>
    </head>
    <body>
    <div id="printarea">Print this stuff.</div>
    <a href="javascript:void(0);" onclick="displayHTML(printarea.innerHTML)">Print Preview</a>
    </body>
    </html>

    In mozilla it opens the new window but continues to be thinking about something indefinitly. In Safari the new window opens but there is no content. In IE it seems to work fine. I haven't tested NS yet, nor have I tested any of this on a PC.

    Thanks for any help.

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,466
    Thanks
    3
    Thanked 495 Times in 482 Posts
    PHP Code:

    <script LANGUAGE="JavaScript">
    function 
    displayHTML(printContent) {
    var 
    inf printContent;
    win window.open("print.htm"'popup''toolbar = no, status = no');
    win.document.write(inf);
    win.document.close(); // new line
    }
    </script> 

  • #3
    New Coder
    Join Date
    Feb 2005
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you. That helped the problem in FF. I am still not getting anything in Safari.

  • #4
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,466
    Thanks
    3
    Thanked 495 Times in 482 Posts
    cant test with safari

    but what is the contet of print.htm

    try writing the complete HTML to the popup

    win = window.open(' ', 'popup', 'toolbar = no, status = no');

  • #5
    New Coder
    Join Date
    Feb 2005
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I did try that and it still didn't work. I also just tested in NS and it didn't work there either. I get a JS error message "printarea is not defined".

    print.htm is just an empty document. I created it because the original script that i was working from wasn't calling any file at all and I always got an alert that the file couldn't be found.

  • #6
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,466
    Thanks
    3
    Thanked 495 Times in 482 Posts
    dont know how missed this

    <a href="javascript:void(0);" onclick="displayHTML(document.getElementById('printarea').innerHTML)">Print Preview</a>

  • #7
    New Coder
    Join Date
    Feb 2005
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    haha...i just came back to say that i solved the problem in NS with this fix. I layed down to take a nap and it came to me just as i was falling asleep. Unfortunatly it still doesn't work in Safari. Also, the print() doesn't seem to work in IE. I added this....
    win.document.write(inf + "<br /><a href='javascriptrint()'>print</a>");
    and it works except in IE(and Safari of course).

  • #8
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,466
    Thanks
    3
    Thanked 495 Times in 482 Posts
    '<span onclick="print();">print</span><br>',

  • #9
    New Coder
    Join Date
    Feb 2005
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for all your help.

  • #10
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,959
    Thanks
    0
    Thanked 236 Times in 233 Posts
    You can print selected parts of the page by using CSS and without using javascript at all.

    http://wsabstract.com/dhtmltutors/cssmedia2.shtml

  • #11
    New to the CF scene
    Join Date
    May 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You may try VIEWidget from
    http://hexatech.com/viewidget

    It is a javascript-programmable report & technical drawing generator and print preview control.
    You may use VIEWidget to generate reports or technical drawings,
    display the results in a scrolling and zooming viewer on your web page and then print it.
    It is a very flexible and productive RAD tool as it lets you freely draw tables or
    other objects at arbitrary x-y coordinates.
    Below is a simple Hello World example with two print-preview pages generated:

    //get length unit
    var INCH = control1.getInch();

    //create document
    control1.startDoc();

    control1.drawString(1*INCH, 1*INCH, "Hello World from Page 1");

    //...draw other stuff here

    //create 2nd page
    control1.newPage();
    control1.drawString(1*INCH, 1*INCH, "Hello World from Page 2");

    //...draw other stuff here

    //end document
    control1.endDoc();

    //preview first page (page index=0)
    control1.setCurrentPage(0);
    control1.preview();

  • #12
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    Quote Originally Posted by marshallhansen View Post
    I did try that and it still didn't work. I also just tested in NS and it didn't work there either. I get a JS error message "printarea is not defined".

    print.htm is just an empty document. I created it because the original script that i was working from wasn't calling any file at all and I always got an alert that the file couldn't be found.
    I've just gotta ask.. what is NS? please dont say netscape


  •  

    Posting Permissions

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