N
Nathan Gilbert
I am wanting to use javascript to select between different *.css files
dependent on the user's browser. I am also wanting to generate the
html document containing this javascript dynamically using PERL.
So far, I have the javascript that does what I want to do, and it works
fine as long as the the page was not generated by PERL.
My problem is that when the javascript/html is generated by
my PERL scripts the javascript never gets executed by the clients
browser. Thus, no stylesheets are ever applied to the page.
Some of my code samples:
#########################################################
#the relevant sections from my PERL script:
sub header() {
print "Content-type:text/html\n\n";
print << "HEADER";
<html>
<head>
<title>****</title>
<script type="text/javascript" src="./cssSelect.js"
lanaguage="javascript"></script>
</head>
HEADER
}
#One Note: I have tried using the absolute path in the src tag. Still no
#luck.
#This goes generates rest of html page...
########################################################
#cssSelect.js
var css = (navigator.userAgent.indexOf("MSIE ") != -1 ? "./css1.css" :
../css2.css";
document.write("<link rel='stylesheet' type='text/css' href='" + css +
"' />");
#As mentioned before, this works fine when not being generated by a PERL
script.
Getting javascript to execute after being generated by PERL seems to be
a problem other people have run into over the years, but I haven't been able
to find a solution that works in my case.
Thanks in advance,
NG
dependent on the user's browser. I am also wanting to generate the
html document containing this javascript dynamically using PERL.
So far, I have the javascript that does what I want to do, and it works
fine as long as the the page was not generated by PERL.
My problem is that when the javascript/html is generated by
my PERL scripts the javascript never gets executed by the clients
browser. Thus, no stylesheets are ever applied to the page.
Some of my code samples:
#########################################################
#the relevant sections from my PERL script:
sub header() {
print "Content-type:text/html\n\n";
print << "HEADER";
<html>
<head>
<title>****</title>
<script type="text/javascript" src="./cssSelect.js"
lanaguage="javascript"></script>
</head>
HEADER
}
#One Note: I have tried using the absolute path in the src tag. Still no
#luck.
#This goes generates rest of html page...
########################################################
#cssSelect.js
var css = (navigator.userAgent.indexOf("MSIE ") != -1 ? "./css1.css" :
../css2.css";
document.write("<link rel='stylesheet' type='text/css' href='" + css +
"' />");
#As mentioned before, this works fine when not being generated by a PERL
script.
Getting javascript to execute after being generated by PERL seems to be
a problem other people have run into over the years, but I haven't been able
to find a solution that works in my case.
Thanks in advance,
NG