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

I'm not sure if this question was asked before (at least I did not see it) but can one manipulate browser behaviour using PERL (something similar to JAVA's open.window() routine)?

If so, what would be a simple example or better yet, where would I find some 'man pages' on that?

P.S. To be clear what I have in mind: I wrote a few scripts which return results from MySQL queries. I would like to open the results in a seperate window upon running my script in preferably predefined size and without tool bar and so on. I tried Java's open.window() but it seems like it does not like dynamic pages (it works fine if the page already exists).

Thanks.

Replies are listed 'Best First'.
(ar0n) Re: Browser manipulation using PERL?
by ar0n (Priest) on Oct 30, 2000 at 18:37 UTC
    (it's Perl, not 'PERL')

    You can specify a target window in which the results of the submitted query will be displayed:
    <form method="post" action="/cgi-bin/script.pl" target="blah"> <input type="text" name="txt" size="10"> <input type="submit" value="stumbit"> </form>
    This will open a new window with 'blah' as its name, or if the window 'blah' already exists, point it to the results. You can not, however, specify size and toolbar et cetera.

    To do that, you'd have to use some sort of a javascript solution, which - IMHO - isn't such a swell idea, since you'd have to rely on the browser to support javascript...

    [ar0n]

Re: Browser manipulation using PERL?
by Fastolfe (Vicar) on Oct 30, 2000 at 19:42 UTC
    I think perhaps you're confusing the abilities of Perl with something like JavaScript. In a CGI/web server environment, Perl scripts execute on the server, and simply return content to the browser. JavaScript can be a part of that content, but is always executed on the browser side. That's how JavaScript can affect the behavior of the browser; the browser is the one executing the code. Perl can't do that, because the browser never sees the Perl code. All the browser gets is the output of the Perl script.

    The other posts in this thread should help you on your way. There's no reason window.open() shouldn't work with dynamic code, and simply specifying a target="..." attribute for certain tags will put content in other windows without needing to explicitely create them using JavaScript. Either of these techniques should work across browsers (though if they don't have JavaScript enabled...)

Re: Browser manipulation using PERL?
by elwarren (Priest) on Oct 30, 2000 at 19:42 UTC
    I'm not sure if you want to spawn the window from the client side or from the server side. If you're serving up a page to a web client you could use the target method or javascript to spawn new windows. This can be done with a form button or automatically when the page loads with meta tags. Here is the javascript command to do this:
    window.open('http://page.to/load/','NewWindowTitle', 'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=300,height=300')
    If you want to control the browser on the same machine as your database you have two options that I'm aware of. First is to just execute the command with the url as an argument.
    netscape http://page.to/load/
    Your second option is to control the browser. On win platforms you could do this with OLE. Check out the excel demo that comes with activestate perl. In unix the api used to be available to compile C programs against.

    Wish I had more details but maybe this could get you started.
      I think I wasn't clear enough. I am not calling a new window from a from. I'm calling it from a link in this form: <blockqoute>
      <a href=\"/cgi-bin/site_group.pl?t_where=$website\" target=website>$we +bsite</a>
      I tried different various on java but so far without a success. The only one that works is the link above (using a simple 'target' clause). That, however, does not give me an options of removing all other bells and whistles associated with a browser window. So, I tried this:
      <a href=\"onClick=\"window.open(\"/cgi-bin/site_group.pl?t_where=$webs +ite\",'Visited Sites','toolbar=no, location=no,directories=no,status=yes,menubar=no, scrollbars=yes,resizable=yes,width=300,height=300')\" \">$website</a>
      but without any success. I will try different variations to see which one works.
Re: Browser manipulation using PERL?
by wardk (Deacon) on Oct 30, 2000 at 19:31 UTC

    Javascript's open window handles dynamic scripts just fine.

    While I try to avoid using javascript wherever possible, using it for the simple opening and closing of separate windows is I believe a safe and logical usage. I cannot imagine these basic calls becoming part of the MS/NS browser wars

Re: Browser manipulation using PERL?
by jynx (Priest) on Oct 30, 2000 at 23:01 UTC
    i have a gift for the obvious, so please bear with me (since you've probably already tried this):
    Have you looked at the HTML tags for targeting?

    target=_top target=parent

    parent will rewrite the current window, and _top will open a new window for you. These are netscape implementations, and probably don't work the same on IE, but it's worth a shot...

    jynx

Re: Browser manipulation using PERL?
by bman (Sexton) on Oct 30, 2000 at 22:05 UTC
    I think I wasn't clear enough. I am not calling a new window from a from. I'm calling it from a link in this form:
    <a href=\"/cgi-bin/site_group.pl?t_where=$website\" target=website>$we +bsite</a> </blockquote>
    I tried different various on java but so far without a success. The only one that works is the link above (using a simple 'target' clause). That, however, does not give me an options of removing all other bells and whistles associated with a browser window. So, I tried this:
    <a href=\"onClick=\"window.open(\"/cgi-bin/site_group.pl?t_where=$webs +ite\",'Visited Sites','toolbar=no, location=no,directories=no,status=yes,menubar=no, scrollbars=yes,resizable=yes,width=300,height=300')\" \">$website</a>
    but without any success. I will try different variations to see which one works.
      Instead of
      <a href=\"onClick=\"window.open(\"/cgi-bin/site_group.pl?t_where=$website\",'Visited Sites','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=300,height=300')\"\">$website</a>, try
      <a href='#' onClick=\"window.open('/cgi-bin/site_group.pl?t_where=$website', 'Visited Sites', 'scrollbars=yes,resizable=yes,width=300,height=300')\">$website</a>

      Btw, that's still javascript. It just happens that perl is sending it out with the rest of the output to your web browser.

      ALL HAIL BRAK!!!

        Thank you. '#' was what I was looking for. :-)