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

I want to run a JavaScript function located in the header. According to the documentation in CGI.pm, start_html is a "Canned HTML header" which can contain the following parameters (I've left other parameters out):
# $title -> (optional) The title for this HTML document (-title)
# $script -> (option) Javascript code (-script)
# $head -> (optional) any other elements you'd like to incorporate into the <HEAD> tag (a scalar or array ref)
# @other -> (optional) any other named parameters you'd like to incorporate into the <BODY> tag.
Here is the JavaScript I want to run along with the perl script I've used:
print start_html ( -title=>'quiz', -script=>{ -language=>'JAVASCRIPT', <!-- function winopen(){ newwin=window.open("","","scrollbars") if (document.all){ newwin.moveTo(0,0) newwin.resizeTo(screen.width,screen.height) } } //--> } -BGCOLOR=>'beige' -onLoad=>'winopen()' );
The CGI.pm documentation is not clear on putting a function in the <HEAD> section. It says:
$head -> (optional) any other elements you'd like to incorporate into the <HEAD> tag (a scalar or array ref)
but it doesn't explain how to do this. I want a new window to open when the user loads this page. Can anyone provide some guidance and correct my script? Many Thanks.
Chris

Replies are listed 'Best First'.
Re: Javascripts in HTML header
by larsen (Parson) on Dec 27, 2001 at 18:31 UTC
    You're not BooK to speak more than a language at the same time :)). You have to quote you Javascript to produce a correct header:
    print start_html ( -title=>'quiz', -script=>{ -language=>'JAVASCRIPT', -code => qq| <!-- function winopen() { newwin=window.open("","","scrollbars") if (document.all){ newwin.moveTo(0,0) newwin.resizeTo(screen.width,screen.height) } } //--> | } -BGCOLOR=>'beige' -onLoad=>'winopen()' );
A reply falls below the community's threshold of quality. You may see it by logging in.