why is this code not working - printing a pop up

Discussion in 'Javascript' started by Asad Khan, Jun 3, 2004.

  1. Asad Khan

    Asad Khan Guest

    It makes all the sense in the world, but its not working. Any idea why?
    Click the popup button to popup a new screen, and then click the print
    button on the popup (which doesn't do anything!).

    <html>

    <head>
    <title>UGH!</title>

    <script type="text/javascript">

    function createPrintPageHeader(x) {

    x.document.write("<HTML>\n");
    x.document.write("<HEAD>\n");
    x.document.write("<TITLE>Report</TITLE>\n");
    x.document.write("</HEAD>\n");
    x.document.write("<BODY>\n");

    }
    function createPrintPageFooter(x) {

    x.document.write("</BODY>\n");
    x.document.write("</HTML>\n");

    }

    function doPrint() {

    printWin=open('','printWindow','resizable=no,width=690,height=600,menuba
    r=yes,status=yes,scrollbars=yes');
    createPrintPageHeader(printWin);

    printWin.document.write('foo');

    printWin.document.write('<form>');
    printWin.document.write('<input type=\"button\" value=\"Print contents
    of popup\" onclick=\"self.print()\">');
    printWin.document.write('</form>');

    createPrintPageFooter(printWin);

    }

    </script>
    </head>

    <body>
    <p>This is just a paragraph. </p>
    <form>
    <input type="button" value="PopUp" name="btnPopUp"
    onclick="doPrint()"></p>
    </form>
    </body>
    </html>


    *** Sent via Devdex http://www.devdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Asad Khan, Jun 3, 2004
    #1
    1. Advertising

  2. > It makes all the sense in the world, but its not working. Any idea why?
    > Click the popup button to popup a new screen, and then click the print
    > button on the popup (which doesn't do anything!).
    >
    > printWin.document.write('<form>');
    > printWin.document.write('<input type=\"button\" value=\"Print contents
    > of popup\" onclick=\"self.print()\">');
    > printWin.document.write('</form>');
    >


    You can better use window.print();

    Also it would be more compatible if you use printWin.document.open();
    before you write the HTML and printWin.document.close(); after all the
    content is written.

    The rest looks fine to me.
     
    Vincent van Beveren, Jun 3, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    8,568
    Randy Webb
    Feb 4, 2006
  2. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    925
    Mark Rae
    Dec 21, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,090
    Smokey Grindel
    Dec 2, 2006
  4. samppi
    Replies:
    27
    Views:
    515
    David A. Black
    Dec 5, 2007
  5. Replies:
    1
    Views:
    123
    Martin Honnen
    Sep 26, 2003
Loading...

Share This Page