http://www.perlmonks.org?node_id=255126

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

Hi all,
I’m sorry if this has been asked before.
I just need to obtain a better understanding of CGI.pm
I have a script that outputs dynamic results information back to the web browser.
What I like to know is:-
How would I redirect the output to a new browser window?
I have tried looking around and I believe this is not as simple as it sounds.
I have viewed the CGI.pm help notes and see that this has a –target option but clearly
stats that it does not work on Internet Explorer.

What I need to establish is:-
1, Is CGI.pm what I need?
2, Do I need to combined CGI.pm with some sort of JavaScript?
3, Is this type of thing limited to ether Netscape or Explorer and not both?
4, Is there any good resource I could look at for help with this?

I guess the simplest example I could give for what I am trying to achieve is:

#!/usr/bin/perl print "Content-type: text/html\n\n\n"; print <<END; #### FROM HERE TO END IN NEW BROWSER WINDOW <html> <font color=RED> hello World </font> </html> END

Replies are listed 'Best First'.
Re: Perl output to new browser window?
by chromatic (Archbishop) on May 02, 2003 at 19:14 UTC

    This isn't the job of Perl or CGI. It's the domain of the web browser to decide when and how to create new windows. There's no information in a normal HTML document that says "by the way, this is a new window now".

    That said, there are a couple of answers. One is to change the link target -- if you're using a GET request -- to pop up a new window. Another option is to use JavaScript to open a new window.

    Of course, that will depend on how the user has configured his browser and how well said browser supports JavaScript.

Re: Perl output to new browser window?
by LordWeber (Monk) on May 02, 2003 at 19:16 UTC
    Re: Perl output to new browser window?
    by LordWeber (Monk) on May 02, 2003 at 21:03 UTC
      Re: Perl output to new browser window?
      by Anonymous Monk on May 02, 2003 at 20:14 UTC
        Ok thanks for your comments.

        But I am now very confused I found the below code @
        http://www.wiley.com/legacy/compbooks/stein/source.html

        Which runs a perl script opening a pop window?
        So could you clear up my confusion please?
        Can I use CGI.pm or not?
        Regards
        Gareth

        #!/usr/bin/perl #file: frames.pl use CGI qw/:standard/; print header, start_html('Popup Window'); if (!param) { print h1("Ask your Question"), start_form(-target=>'answer'), "What's your name? ",textfield('name'), p(), "What's the combination?", checkbox_group(-name=>'words', -values=>['eenie','meenie','minie','moe'], -defaults=>['eenie','moe']), p(), "What's your favorite color? ", popup_menu(-name=>'color', -values=>['red','green','blue','chartreuse']), p(), submit, end_form; } else { print h1("And the Answer is..."), "Your name is ",em(param(name)), p(), "The keywords are: ", em(join(", ",param('words'))), p(), "Your favorite color is ",em(param('color')); } print end_html;

          The key line there is start_form(-target=>'answer'). The 'target' attribute tells the browser which window to display the response in. If a window with the specified name doesn't exist, a new window will be created.

          90% of every Perl application is already written.
          dragonchild
      Re: Perl output to new browser window?
      by Anonymous Monk on May 02, 2003 at 20:28 UTC
        Hi all
        Thanks all. i have got my head around it at last
        Thanks all

        Regards
        Gareth