javascript print() not working in new window

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Asad

    #1

    javascript print() not working in new window

    I have a main window that creates a new window called printWin (which
    contains the printable format of the page). From the main window I
    embed a javascript in the printWin window that calls the
    "window.print() " function. So it looks like this:

    printWin.docume nt.write ("<FORM>");
    printWin.docume nt.write ("<INPUT TYPE=\"BUTTON\" NAME=\"btnPrint \"
    VALUE=\"Print\" ONCLICK=\"javas cript:window.pr int()\">");
    printWin.docume nt.write ("</FORM>");

    But this has absolutely no effect when clicked. I tried printing out
    the window name, but it was blank. I dont know why that is. Maybe its
    coz I'm dynamically creating the new window? BTW, if its of any
    relevance, I copy the body of the main window into printWin and then
    make some changes to it (basicallly convert all text boxes into text).

    Any ideas?
  • Richard Cornford

    #2
    Re: javascript print() not working in new window

    Asad wrote:
    <snip>[color=blue]
    > printWin.docume nt.write ("<FORM>");
    > printWin.docume nt.write ("<INPUT TYPE=\"BUTTON\" NAME=\"btnPrint \"
    > VALUE=\"Print\" ONCLICK=\"javas cript:window.pr int()\">");
    > printWin.docume nt.write ("</FORM>");[/color]
    <snip>[color=blue]
    > Any ideas?[/color]

    Once you have written to the document in the new window, do you close
    the document using - printWin.docume nt.close() - ?

    Richard.


    Comment

    • Asad Khan

      #3
      Re: javascript print() not working in new window

      Ok something better but even more wierd ...

      The javascript is in my main window. In there I create the new window as
      follows:


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

      This window's name is clearly printWindow. Anyways, further down I have
      this code:

      var c = printWin.docume nt.createElemen t("center");
      var foo = printWin.docume nt.createElemen t("form");
      var btnPrint = printWin.docume nt.createElemen t( 'button' );
      btnPrint.setAtt ribute("name", "p");
      btnPrint.setAtt ribute("value", "Print");
      btnPrint.setAtt ribute("onclick ", "executePrint() ");
      btnPrint.onclic k=function(){pr intWin.print(); };
      var btnClose = printWin.docume nt.createElemen t( 'button' );
      btnClose.setAtt ribute("name", "c");
      btnClose.setAtt ribute("value", "Close");
      btnClose.onclic k=function(){pr intWin.close(); };
      foo.appendChild ( btnPrint );
      foo.appendChild ( btnClose );
      c.appendChild( foo );
      printWin.docume nt.body.insertB efore
      (c,printWin.doc ument.body.firs tChild);

      This creates two buttons on top of my new (print) window. The wierd
      thing is that close button works fine! It closes the print window that
      has been created (popped up). However, the print button has no effect
      whatsoever!

      I tried window.print() but that causes the original main window to get
      printed. And I also tried printWindow.pri nt() for which I get this dumb
      error saying printWindow is undefined.

      Also, since these buttons are dynamically generated they dont appear in
      the view source of my pop up, but I doubt thats got anything to do with
      it.

      So how do I get the print screen to print properly using this button?






      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      Working...