in reply to call javascript from perl

One way to do this is by invoking the perl script on an iframe, the script returning html with a javascript that dumps the info into the main html page by calling a javascript method there defined.

In other words:
Create the page's html with an invisible iframe like this <iframe src="your script" width="0" height="0">, and a javascript method, lets say Dumper.

Create your script that does whatever it has to do, and then output html code with a javascript function that holds the info you want to display and passes it to the Dumper function by calling parent.Dumper(txt);

In code:
Main page's HTML ... <script language="javascript"> function Dumper(txt) { // write txt somewhere on the page } </script> ... <iframe src="perlscript.pl" width=0 height=0> ....
Now the the BODY for the HTML returned by the script
<body> <script language="javascript"> var txt='the info you want to show'; parent.Dumper(txt); </script> </body> ...

Replies are listed 'Best First'.
Re^2: call javascript from perl
by pvilleSE (Novice) on Feb 10, 2006 at 13:41 UTC
    Thank you all for your advise, I tried what olus said but I couldn't get it to execute my script command, what I ended up doing is a sort of redirect back to my original page which then calls my javascript to reload the data.

    if($ENV{'HTTP_REFERER'}=~ m/results=results/i)
    {
    print "Location:".$ENV{'HTTP_REFERER'}."\n\n";
    }
    else
    {
    print "Location:".$ENV{'HTTP_REFERER'}."?results=results\n\n";
    }

    this seems to be the easiest way to get the browser to call a javascript after you are done with a perl function. If someone wanted to use this to call a javascript function you just need to make an html page to call it and put the address where I put ENV{'HTTP_REFERER'}.