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

I have been using 'print header(-refresh=>$url)' to change pages, but I really want to open a new window for the new location. I haven't found anything that does that yet. I have tried to apply Window-target: with Location:, but that doesn't seem to work the way I am using it. Is there a way to do this?

Replies are listed 'Best First'.
Re: Change location in new window
by ikegami (Patriarch) on Nov 25, 2006 at 07:21 UTC

    It must be done before the request is started. It's too late by the time your script executes. By using the target attribute on the <form> or <a> tag, the script specified by the action or href attribute will load in a new window.

    <form target="_blank" action="..." ...> ... </form>

    or

    <a target="_blank" href="..." ...>...</a>
Re: Change location in new window
by osunderdog (Deacon) on Nov 25, 2006 at 07:28 UTC

    In the CGI docs, look under the heading "WORKING WITH FRAMES". There's a statement in there that says:

    You may provide a -target parameter to the header() method: print $q->header(-target=>'ResultsWindow'); ... If a frame of that name doesn't already exist, the browser will pop up + a new window and load your script's document into that. ...

    Hazah! I'm Employed!

      Interesting. That outputs a non-standard HTTP header. Any idea how well it is supported?

      It's not mentioned in the HTML spec either. The only mention I've found on the IETF or W3 sites is to an old draft RFC.

Re: Change location in new window
by bradley (Initiate) on Dec 01, 2006 at 18:04 UTC
    I tried the suggestions, and here is what I found. Opening a window is not problem when using a form. However, I want this to be automatic, not requiring the viewer to have to click on something. And I haven't found anything that would allow for a n automatic submission of a form.

    When I tried using the -target parameter in the header, I couldn't get it to work in either Netscape, Firefox, or Safari. (I didn't bother to test it in IE because it has to work for all common browsers, or not at all.)

    On the server I use, there are a ton of CGI packages, and I haven't had time to wade through them all; maybe there is an answer there. I am currently trying to use two CGI objects to see if that would work, but as yet, I haven't found a way to cause them to operate in two different windows.