Thread Javascript und CGI wollen nicht miteinander (13 answers)
Opened by gmafx at 2011-05-06 15:51

Linuxer
 2011-05-07 00:37
#148311 #148311
User since
2006-01-27
3890 articles
HausmeisterIn

user image
Jap, hast recht. Ich hatte gar nicht so auf den Perl-Code geachtet.

perldoc CGI
...
The <script> tag, has several attributes including "type", "charset" and "src". "src" allows you to keep JavaScript code in an external file. To use these attributes pass a HASH reference in the -script parameter containing one or more of -type, -src, or -code:
Code: (dl )
1
2
3
4
5
6
7
8
9
    print $q->start_html(-title=>'The Riddle of the Sphinx',
-script=>{-type=>'JAVASCRIPT',
-src=>'/javascript/sphinx.js'}
);

print $q->(-title=>'The Riddle of the Sphinx',
-script=>{-type=>'PERLSCRIPT',
-code=>'print "hello world!\n;"'}
);

A final feature allows you to incorporate multiple <script> sections into the header. Just pass the list of script sections as an array reference. this allows you to specify different source files for different dialects of JavaScript. Example:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
     print $q->start_html(-title=>'The Riddle of the Sphinx',
-script=>[
{ -type => 'text/javascript',
-src => '/javascript/utilities10.js'
},
{ -type => 'text/javascript',
-src => '/javascript/utilities11.js'
},
{ -type => 'text/jscript',
-src => '/javascript/utilities12.js'
},
{ -type => 'text/ecmascript',
-src => '/javascript/utilities219.js'
}
]
);

The option "-language" is a synonym for -type, and is supported for backwards compatibility.

The old-style positional parameters are as follows:
...



Test:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
perl -MCGI -wle '$q = CGI->new;  print $q->start_html( -script => [ { -language => "javascript", type => "text/javascript", -src => "js/js.js" }, { -code => "bliblablubb" } ] )'
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title>Untitled Document</title>
<script src="js/js.js" type="text/javascript"></script>
<script type="text/javascript">//<![CDATA[
bliblablubb
//]]></script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
meine Beiträge: I.d.R. alle Angaben ohne Gewähr und auf Linux abgestimmt!
Die Sprache heisst Perl, nicht PERL. - Bitte Crossposts als solche kenntlich machen!

View full thread Javascript und CGI wollen nicht miteinander