lev has asked for the wisdom of the Perl Monks concerning the following question:
The perl cgi code in the html body used here to call a javascript function has worked for me before in passing arguments to a js function. My intension here was to have an 'else (if)' or two in the function to control different windows by means of the agruments passed.
However, when applying the code indirectly(lower button) to open a window or to bring it forward if already open, it failed, while calling the same function directly(upper button) within the document form did work.
In particular, using a PC with either Explorer or Firefox, both indirect and direct routes opened a window, but only the direct route could bring the window forward if it was already open. Using a Mac with Firefox, the direct route worked well both to open or to bring forward an existing window, but the indirect route did nothing. On the other hand, when using a Mac with the Safari browser, both routes worked well to open a window and keep it on top.What do I change or add to get full functionality for the indirect route with the Firefox and Explorer browsers as I get with Safari?
Here's the code:
#!/usr/bin/perl -w use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); use strict; my $query = new CGI; my $JSCRIPT=<<EOF; function sub_dispatcher(passit) { document.sql_tool.submit(); } var myRef; function windo(arg){ var url = 'http://bioinfo.weizmann.ac.il/safety/images/db_connect_qfi +le.htm'; if(myRef == null || myRef.closed){ myRef = window.open(url,'mywin','left=20,top=20,width=500,height=5 +00,resizable=1,scrollbars=1'); }else if(!myRef.closed){ myRef.focus(); myRef.location.reload(true); } } EOF ; #------------------------------- #SETTING UP A FORM FOR INPUT: print $query->header(); print $query->start_html(-title => 'Selection ', -BGCOLOR=>'lavender', -script=>$JSCRIPT); print $query->startform(-name=>'sql_tool'); #SETTING UP A FORM FOR INPUT: print $query->button(-name=>'listfile', -value=>'direct function-call', -onClick=>'windo("win")' ),p; print $query->button(-name=>'embedvar', -value=>'indirect function-call', -onClick=>"sub_dispatcher('call_windo')" ),p; print $query->endform(), hr; #------------------------------------------------------ #JS FUNCTION CALL: my $writsql= "-code=>\'windo(\"no_win\")\'}),p"; my $prntvar = "print \$query->start_html(-script=>{-l +anguage=>\'JavaScript',$writsql; \n"; eval $prntvar; print end_html;Thanks for any guidance on this.
- Comment on Calling a js function from within a cgi script to open a window
- Download Code
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Calling a js function from within a cgi script to open a window
by ikegami (Patriarch) on Jul 14, 2011 at 18:25 UTC |