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

I have a perl cgi script which parses a form, and creates output in the browser window from which the form was submitted. I want to open another window as well, one which is non-existent until the script opens it.
The html "target" thingy doesn't seem to work, and I can't get one to open using javascript either.
Mind you, I don't really know what I am doing.
I probably haven't even explained my problem very well ...

Trying javascript

print "<script>\n"; print "function open_window(url) \{\n"; print "mywin = window.open(url,\"win\",'toolbar=0,location=0,directori +es=0,statu s=0,menubar=0,scrollbars=0,resizable=0,width=520,height=350')\;\n"; print "\}\n"; print "</SCRIPT>\n"; print "mywin.document.write('WriteThisToTheNewWindow')\;\n";

trying "target"
print "<a href=http://www.perlmonks.org target=window2></a>\n";

Replies are listed 'Best First'.
Re: CatsPaw
by synapse0 (Pilgrim) on Sep 20, 2001 at 15:25 UTC
    This is purely a javascript thing. You just print your javascript source in <script language='javascript'> code </script> tags and the browser takes care of the rest, the server and perl have no ability to affect how the browser handles the javascript code. In your particular instance, the target anchor would do nothing, since the link would have to be clicked on to open the other window, and you don't have any link text. The javascript you have would also do nothing, since you declared the open_window function, but never executed it. Check your javascript references again and try writing your javascript code in a static html page and get that working first.
    -Syn0
Re: CatsPaw
by earthboundmisfit (Chaplain) on Sep 20, 2001 at 16:56 UTC
    Not a Perl problem, but the simple solution to the JS problem is to remove the function definition so the window.open method executes inline:
    print <<END_JS; <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"> var url = 'http://perlmonks.com/' var mywin = window.open(url,"win","toolbar=0,location=0,directories= +0,status=0,menubar=0,scrollbars=0,resizable=0,width=520,height=350") </SCRIPT> END_JS
    You might want to check out Here document formatting
Re: CatsPaw
by George_Sherston (Vicar) on Sep 20, 2001 at 14:32 UTC
    I'd be very intersted to know (if there is one) the perl solution. But I think this is really a javascript / HTML problem. I'm not sure whether you want to put all the output from the CGI into a new window, or split the output, partly in the old window and partly in the new. If it's the former, then, pace your remark that it doesn't work, the HTML target thingy is what you want, as in <FORM TARGET="_NEW" .. >. If it's the latter, my solution wd be to output the following to the old browser window:
    <head> ... <script> function opener() { window.open('your_page.html','new'); } </script> </head> <body onload="opener()"> ...
    ... though of course in order to output this you should use CGI or die;.

    § George Sherston
Re: CatsPaw
by tommyw (Hermit) on Sep 20, 2001 at 14:32 UTC

    Well, the second version is just creating a normal html link, and will only activate when the user clicks on it. Not having anything between the tags for them to click on makes this a little hard.

    I don't know javascript, so I can't comment on the first. But initially, forget about perl or cgi: draft up a static page with the HTML you require, and then just wrap print statements around it (with suitable escapes, and variables inserted, of course)