Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Javascripts in HTML header

by chriso (Sexton)
on Dec 27, 2001 at 18:14 UTC ( [id://134604]=perlquestion: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://134604]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-20 14:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found