Hello Monks,

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.


In reply to Calling a js function from within a cgi script to open a window by lev

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.