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

I'm just now attempting to put javascript into my perl code using CGI.PM. I've got the appropriate code, so I won't put it here. In IE, it seems to be working fine, but in Mozilla, on the webpage displayed in Mozilla, the first line I see is:

//]]> End script hiding -->

Have I found some kind of browser difference that CGI.PM is sensitive to? I can put the code here if needed.

I think you probably will want to see the code. Also, when I say that in IE its fine, I meant that it doesn't display this anomaly. I do have some problems that I need to correct in my javascript, but that shouldn't affect this. Here is my code that puts the javascript in place.

$JSCRIPT=<<END; <script language="JavaScript"> input.value = max; textarea.focus(); function count(e, textarea, max, input) { if (!e.which) keyCode = event.keyCode; // ie5+ op5+ else keyCode = e.which; // nn6+ if (textarea.value.length<max+1) input.value = max - textarea.value.length; else { textarea.value = textarea.value.substring(0,max); input.value = 0; alert("Text size exceeded, results may be truncated"); return false; } } </script> END print $cgi->start_html( -style=>{'code'=>$STYLE}, -meta=>{ "Security" => "Confidential-Internal", "Description" => "IBM Record of Qwest Secalert", "Keywords" => "secalert,data_collect", "Content-Type" => "text/html; charset=iso-8859-1", "Pubisher" => "IBM Global Services at Qwest" }, -title=>"$title", -script=>$JSCRIPT );

Replies are listed 'Best First'.
Re: Javascript difference in Mozilla
by Fletch (Bishop) on Mar 30, 2007 at 18:25 UTC

    If you read the manual, the argument to -script should be the text of your Javascript code; the start_html method will wrap it in appropriate <script> tags for you.

    -script should point to a block of text containing JavaScript function definitions. This block will be placed within a <script> block inside the HTML (not HTTP) header.

    What you're probably seeing is the extra straggling content which has been wrapped around your script section (CGI.pm's starts it; your start is ignored; yours closes the script tag; CGI.pm's comment-to-hide-from-old-browsers line is shown, and it's extra ending </script> is hidden).

Re: Javascript difference in Mozilla
by derby (Abbot) on Mar 30, 2007 at 18:48 UTC

    Fletch all ready answered your question but when I run into these situations, I find it more useful to use another program (such as GET, curl, or wget) to look at the html and headers in plain-text.

    -derby
Re: Javascript difference in Mozilla
by un-chomp (Scribe) on Mar 30, 2007 at 22:12 UTC
    here-docs + CGI.pm can sometimes be a painful way of generating HTML - alternatives include Template which is well worth a look if you haven't already seen it.
Re: Javascript difference in Mozilla
by gam3 (Curate) on Apr 01, 2007 at 12:06 UTC
    There are some plugins for firefox that can help figure out what headers are coming across the line. To see what headers are coming in you can use live HTTP headers.

    The Web Developer plugin can show you all the javascript on a single page.

    -- gam3
    A picture is worth a thousand words, but takes 200K.