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

I am writing a cgi program and instead of outputting HTML code to the client want to execute a javascript function in the active client HTML page Is this possible and would it involve socket programming.
  • Comment on How to run Javascript function from Perl script

Replies are listed 'Best First'.
How to run Javascript function from Perl script
by gaggio (Friar) on Aug 08, 2000 at 21:31 UTC
    With a Perl CGI script, you generate an HTML page. This page, can of course contain some JavaScript function inside <SCRIPT> tags...

    So... you can execute any JavaScript function from a CGI script if you use a JavaScript OnLoad() function in the <BODY> tag.

RE: How to run Javascript function from Perl script
by gaggio (Friar) on Aug 08, 2000 at 21:34 UTC
    I'm sorry. The page is corrupted because I forgot to place the "greater than" and "less than" character inside CODE tags. I can't update my comment anymore :-(
Re: How to run Javascript function from Perl script
by gregorovius (Friar) on Aug 08, 2000 at 22:22 UTC
    You would need to run a Java applet on the browser in order to be able to send commands to an HTML page without replacing it. Your perl program wouldn't be a CGI, but a standalone server interacting with the Java applet. For this you can use the NetServer::Generic module instead of dealing with sockets yourself.

    On making the applet execute your javascript function you should check java.sun.com for documentation. I'm sure it's not hard to do what you want.