window.print() doesn't work!?

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

    window.print() doesn't work!?

    First of all, this one is driving me crazy, so thanks in advance for any
    help!!

    I've got a javascript function in a parent document that generates an HTML
    document on the fly when a button is clicked... that generated popup
    contains a button that's supposed to print the contents of the popup window
    (self). However, the button won't print (nothing happens on click) from the
    newly generated popup to print the contents of the window... the complete
    source for the generated page is below, I've tried every combination I can
    think of, but absolutely nothing happens when I click the button... I tried
    the right-click print from the context menu, and everything comes up... so,
    the issue's in code somewhere! argh!

    <HTML>
    <HEAD>
    <TITLE>Generate d 2/19/2004 at 14:18</TITLE>
    </HEAD>
    <BODY bgcolor='#FFFFF F' text='#000000' style='margin: 0em'>
    <DIV ALIGN='center'>
    <IMG SRC=graphs/ChartPic_000001 .jpeg width=600 height=300>
    <form>
    <input type=button value="Print Document" onclick="window .print()">
    </form>
    </DIV>
    </BODY>
    </HTML>


    ...and just in case someone is interested in the code that generates this
    window in the parent page... it's below...



    <!-- Begin
    function popUp(URL,TITLE ,IMGWIDTH,IMGHE IGHT,WINWIDTH,W INHEIGHT) {
    day = new Date();
    id = day.getTime();
    dateTime = day.getMonth()+ 1 +'/'+ day.getDate() +'/'+ day.getFullYear () +'
    at '+ day.getHours() +':'+ day.getMinutes( );
    eval("newWindow = window.open('', '"+ id
    +"','toolbar=0, scrollbars=0,lo cation=0,status bar=0,menubar=0 ,resizable=0,wi d
    th=" +WINWIDTH+ ",height=" +WINHEIGHT+ "')");
    newWindow.docum ent.write("<HTM L><HEAD><TITLE> Generated "+ dateTime
    +"</TITLE></HEAD><BODY bgcolor='#FFFFF F' text='#000000' style='margin:
    0em'><DIV ALIGN='center'> <IMG SRC=" +URL+ " width=" +IMGWIDTH+ " height="
    +IMGHEIGHT+ "><form><in put type=button value=\"Print Document\"
    onclick=\"windo w.print()\"></form></DIV></BODY></HTML>")
    newWindow.docum ent.close
    }
    //-->
    </SCRIPT>


  • Craig

    #2
    Re: window.print() doesn't work!?

    OK, I did some additional testing, and if i view source, then save that to
    an .html and open it with NO changes - the code works...

    So, is there something (security?) keeping this function from working from a
    popup window? Is it because I've hidden the toolbar, status, etc?

    "Craig" <someone@micros oft.com> wrote in message
    news:q%8Zb.2646 9$fW.14369@twis ter.rdc-kc.rr.com...[color=blue]
    > First of all, this one is driving me crazy, so thanks in advance for any
    > help!!
    >
    > I've got a javascript function in a parent document that generates an HTML
    > document on the fly when a button is clicked... that generated popup
    > contains a button that's supposed to print the contents of the popup[/color]
    window[color=blue]
    > (self). However, the button won't print (nothing happens on click) from[/color]
    the[color=blue]
    > newly generated popup to print the contents of the window... the complete
    > source for the generated page is below, I've tried every combination I can
    > think of, but absolutely nothing happens when I click the button... I[/color]
    tried[color=blue]
    > the right-click print from the context menu, and everything comes up...[/color]
    so,[color=blue]
    > the issue's in code somewhere! argh!
    >
    > <HTML>
    > <HEAD>
    > <TITLE>Generate d 2/19/2004 at 14:18</TITLE>
    > </HEAD>
    > <BODY bgcolor='#FFFFF F' text='#000000' style='margin: 0em'>
    > <DIV ALIGN='center'>
    > <IMG SRC=graphs/ChartPic_000001 .jpeg width=600 height=300>
    > <form>
    > <input type=button value="Print Document" onclick="window .print()">
    > </form>
    > </DIV>
    > </BODY>
    > </HTML>
    >
    >
    > ..and just in case someone is interested in the code that generates this
    > window in the parent page... it's below...
    >
    >
    >
    > <!-- Begin
    > function popUp(URL,TITLE ,IMGWIDTH,IMGHE IGHT,WINWIDTH,W INHEIGHT) {
    > day = new Date();
    > id = day.getTime();
    > dateTime = day.getMonth()+ 1 +'/'+ day.getDate() +'/'+ day.getFullYear ()[/color]
    +'[color=blue]
    > at '+ day.getHours() +':'+ day.getMinutes( );
    > eval("newWindow = window.open('', '"+ id
    >[/color]
    +"','toolbar=0, scrollbars=0,lo cation=0,status bar=0,menubar=0 ,resizable=0,wi d[color=blue]
    > th=" +WINWIDTH+ ",height=" +WINHEIGHT+ "')");
    > newWindow.docum ent.write("<HTM L><HEAD><TITLE> Generated "+ dateTime
    > +"</TITLE></HEAD><BODY bgcolor='#FFFFF F' text='#000000' style='margin:
    > 0em'><DIV ALIGN='center'> <IMG SRC=" +URL+ " width=" +IMGWIDTH+ " height="
    > +IMGHEIGHT+ "><form><in put type=button value=\"Print Document\"
    > onclick=\"windo w.print()\"></form></DIV></BODY></HTML>")
    > newWindow.docum ent.close
    > }
    > //-->
    > </SCRIPT>
    >
    >[/color]


    Comment

    • Richard Cornford

      #3
      Re: window.print() doesn't work!?

      "Craig" <someone@micros oft.com> wrote in message
      news:q%8Zb.2646 9$fW.14369@twis ter.rdc-kc.rr.com...
      <snip>[color=blue]
      > eval("newWindow = window.open('', '"+ id
      >+"','toolbar=0 ,scrollbars=0,l ocation=0,statu sbar=0,menubar= 0,
      >resizable=0,wi dth=" +WINWIDTH+ ",height=" +WINHEIGHT+ "')");[/color]

      This operation does not require the - eval - function. eval is almost
      never needed in javascript.

      <URL: http://jibbering.com/faq/#FAQ4_40 >

      newWindow = window.open('', id,
      ('scrollbars=ye s,resizable=yes ,width=" +
      WINWIDTH+ ",height=" +
      WINHEIGHT));

      It is never a good idea to open a window that is not resizable, it makes
      no significant difference to the appearance and if not resizable the
      onus is on the programmer to open the window the correct size. There are
      so many variable (and some unknowable) factors involved in determining
      the correct size for a new window that no adequate
      cross-browser/configuration code exists for the task. So the only way of
      guaranteeing that the user will be able to access the content of a
      window is to leave it resizable and preferably enable the scrollbars. If
      any one window feature is specified then any unspecified features will
      be set to off.

      <snip>[color=blue]
      > newWindow.docum ent.close[/color]
      ^^^
      The close function of the document should be called to close the
      document. an expression that does no more that refer to it will not
      achieve that.

      <snip>

      Richard.


      Comment

      • Craig

        #4
        Re: window.print() doesn't work!?

        Yes, Yes, and Yes... I agree with your resizable, I'm going to change that.

        More importantly, you're right about the close... since it wasn't called the
        document was hanging open and IE won't open the print dialog from js while
        the page is still loading... once I got that close on there correctly, it
        worked exactly as expected.

        Thanks so much!

        "Richard Cornford" <Richard@litote s.demon.co.uk> wrote in message
        news:c139nb$fd3 $1$8300dec7@new s.demon.co.uk.. .[color=blue]
        > "Craig" <someone@micros oft.com> wrote in message
        > news:q%8Zb.2646 9$fW.14369@twis ter.rdc-kc.rr.com...
        > <snip>[color=green]
        > > eval("newWindow = window.open('', '"+ id
        > >+"','toolbar=0 ,scrollbars=0,l ocation=0,statu sbar=0,menubar= 0,
        > >resizable=0,wi dth=" +WINWIDTH+ ",height=" +WINHEIGHT+ "')");[/color]
        >
        > This operation does not require the - eval - function. eval is almost
        > never needed in javascript.
        >
        > <URL: http://jibbering.com/faq/#FAQ4_40 >
        >
        > newWindow = window.open('', id,
        > ('scrollbars=ye s,resizable=yes ,width=" +
        > WINWIDTH+ ",height=" +
        > WINHEIGHT));
        >
        > It is never a good idea to open a window that is not resizable, it makes
        > no significant difference to the appearance and if not resizable the
        > onus is on the programmer to open the window the correct size. There are
        > so many variable (and some unknowable) factors involved in determining
        > the correct size for a new window that no adequate
        > cross-browser/configuration code exists for the task. So the only way of
        > guaranteeing that the user will be able to access the content of a
        > window is to leave it resizable and preferably enable the scrollbars. If
        > any one window feature is specified then any unspecified features will
        > be set to off.
        >
        > <snip>[color=green]
        > > newWindow.docum ent.close[/color]
        > ^^^
        > The close function of the document should be called to close the
        > document. an expression that does no more that refer to it will not
        > achieve that.
        >
        > <snip>
        >
        > Richard.
        >
        >[/color]


        Comment

        Working...