gary kuipers has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks:
 
My perl script produces a printable page however ...
 
Instead of having the user go to that page and have to click "back" after printing I would like to open up a new page and write the printable page to it. Then the user can kill the page after printing it and be back on the calling page.
print "<HTML>\n"; print "<HEAD>\n"; print " <script>\n"; print " newWin=window.open\n"; print " </script>\n"; print "</HEAD>\n"; print "<BODY>\n"; print "<CENTER>\n"; etc.
Does not work. I know about
<a href= ... target="_blank">
But I would prefer not to have to write the page to disk and then offer the user a link to it. I'd like to write directly to an newly opened window.
 
Thanks!
 
Gary

Replies are listed 'Best First'.
Re: Opening a new window and writting to it
by nedals (Deacon) on Dec 02, 2004 at 18:19 UTC
    This is not really a Perl question BUT..

    On the assumption that your <doctype> allows you to use 'target', add this link on the page that calls the script.

    <a href="/cgi-bin/yourscript.cgi" target="_blank">

    and the resulting page will be displayed in a new window. You do not have to write the page to disk

Re: Opening a new window and writting to it
by fglock (Vicar) on Dec 02, 2004 at 16:32 UTC

    You can use a state machine. It can be as simple as having a "printable=1" key:

    if ( $printable ) { # print it printable print "<h1>RESULTS</h1>"; } else { print "<p>Welcome to the calling page</p>\n"; print "<a href=xxxx?printable=1 target=\"_blank\">Click for Printa +ble version</a>"; }

    untested, may contain several syntax errors.

Re: Opening a new window and writting to it
by jcarlsson (Novice) on Dec 02, 2004 at 21:05 UTC
    If you can use JavaScript to open a window there are functions for writing HTML in that window, example (some sort of pseudo-code):

    - open new window (get handle for it)
    - write first row in new window (in the same page that you opened the window from
    - write the rest of the rows to the window

    I don't remember the name of the function, but I know that there is such a function (I have used it one or two times), you should check in some javascript forum, they might know what the function is called.

    -- may the source be with you