lev has asked for the wisdom of the Perl Monks concerning the following question:
Two calls, one directly from a form and one indirectly from the html body, reach the same 'window.open' function but only the former works.
The idea behind the simplified script of my post is to select and open one of two windows (files) by pressing one of two buttons. Each button passes a different parameter to the 'open/focus' window function. This function has an argument(arg) place holder to determine which window(file) to open(or focus) when a button is pushed and a corresponding string(argument) is passed. The window function is simply a double function,repeating the same if-else statements. That is, with the function(arg): "if(if-else) else(if-else)", the argument passed to 'arg' will determine if to {open else focus file1(button1)} else to {open else focus file2(button2)} in a new window.
Using a PC with either Explorer or Firefox, both the form button and the button coded in the html body opened a new window, but only the form button could bring the window forward(via 'object.focus') if it was already open. Using a Mac with Firefox, the form button worked well either to open or to bring forward an existing window, but the the button coded in the html body did nothing. Two 'alert's are placed in the window function to show that the html button's call is reaching the window function.
My question is that if this call from the html button passes through the same statements as that of the form button, why does it fail?
Use of a print statement with 'eval' to call a js function from within a script(html body), such as from a subroutine has worked before, but could it be the source of my problem here?
#!/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() { alert('OK-dispatched win2'); document.sql_tool.submit(); } var url1 = 'http://bioinfo.weizmann.ac.il/safety/images/db_connect_qfi +le.htm'; var url2 = 'http://bioinfo.weizmann.ac.il/safety/images/db_connect_qfi +le.txt'; var myRef1; var myRef2; function windo(arg){ if(arg == "win1"){ if(myRef1 == null || myRef1.closed){ myRef1 = window.open(url1,'mywin1','left=20,top=20,width=500,heig +ht=500,resizable=1,scrollbars=1'); }else if(!myRef1.closed){ myRef1.focus(); myRef1.location.reload(true); } }else{ alert('OK-window win2'); if(myRef2 == null || myRef2.closed){ myRef2 = window.open(url2,'mywin2','left=20,top=20,width=500,heig +ht=500,resizable=1,scrollbars=1'); }else if(!myRef2.closed){ myRef2.focus(); myRef2.location.reload(true); } } } EOF ; #SETTING HEADER - HTML: print $query->header(); print $query->start_html(-title => 'Selection ', -BGCOLOR=>'lavender', -script=>$JSCRIPT); #SETTING UP A FORM FOR INPUT: print $query->startform(-name=>'sql_tool'); print $query->button(-name=>'listfile', -value=>'direct function-call', -onClick=>"windo('win1')" ),p; print $query->button(-name=>'embedvar', -value=>'indirect function-call', -onClick=>"sub_dispatcher()" ),p; print $query->endform(), hr; #------------------------------------------------------ #JS FUNCTION CALL: my $writsql= "-code=>\'windo(\"win2\")\'}),p"; my $prntvar = "print \$query->start_html(-script=>{-l +anguage=>\'JavaScript',$writsql;\n"; eval $prntvar; print end_html;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Two calls for the same window function, but one fails?.
by Corion (Patriarch) on Aug 21, 2011 at 13:04 UTC |