473,545 Members | 2,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Executing Javascript generated by PERL

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="java script"></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.user Agent.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
--
"The life of a repoman is always intense."
Jun 26 '06 #1
3 2147
Nathan Gilbert said the following on 6/26/2006 5:33 PM:
I am wanting to use javascript to select between different *.css files
dependent on the user's browser.
You can't as you have no way of reliably determining the browser.
I am also wanting to generate the html document containing this
javascript dynamically using PERL.
OK, then do.
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.
Then PERL is screwing it up somehow as the browser doesn't know, doesn't
need to know, and doesn't care what generated the script.
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.
If you want one set of stylesheets for IE and another for all other
browsers, then use IE conditionals and not javascript for it.

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="java script"></script>
lanaguage? but the language attribute is not needed.

<snip>
var css = (navigator.user Agent.indexOf(" MSIE ") != -1 ? "./css1.css" :
../css2.css";
All three browsers that I use daily will pass the 'MSIE' test but only
one is IE.
#As mentioned before, this works fine when not being generated by a PERL
script.


Then why generate static content with PERL?

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 27 '06 #2
Randy Webb <Hi************ @aol.com> once pondered:
Nathan Gilbert said the following on 6/26/2006 5:33 PM:
I am wanting to use javascript to select between different *.css files
dependent on the user's browser.


If you want one set of stylesheets for IE and another for all other
browsers, then use IE conditionals and not javascript for it.


Thanks for the tip, I replaced the javascript with IE conditionals.
Everything works now the way I intended.

Is there any trick to getting PERL generated javascript to execute in
the user's browser? Can someone point out a tutorial that explains how
and when most browsers parse and execute javascript?

Maybe if I can find out more about how browsers work, I can figure out
why my original method didn't work, just for curiosity.

Thanks in advance,
NG
--
"The life of a repoman is always intense."
Jun 29 '06 #3
There's no problem using "Perl generated" JS; I do it constantly on
various web browsers, with no Perl related problems whatever. Sometimes
people can get into more trouble with dynamically generated JS if they
aren't used to doing that, regardless of what language they're using on
the back end to generate with. I had a tough time when I was starting
out with that stuff.

You might start by checking what the browser is actually getting for
your dynamically and statically generated cases, by using the "view
source" option

Nathan Gilbert wrote:
Randy Webb <Hi************ @aol.com> once pondered:
Nathan Gilbert said the following on 6/26/2006 5:33 PM:
I am wanting to use javascript to select between different *.css files
dependent on the user's browser.


If you want one set of stylesheets for IE and another for all other
browsers, then use IE conditionals and not javascript for it.


Thanks for the tip, I replaced the javascript with IE conditionals.
Everything works now the way I intended.

Is there any trick to getting PERL generated javascript to execute in
the user's browser? Can someone point out a tutorial that explains how
and when most browsers parse and execute javascript?

Maybe if I can find out more about how browsers work, I can figure out
why my original method didn't work, just for curiosity.

Thanks in advance,
NG
--
"The life of a repoman is always intense."


Jun 29 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4941
by: PzYon | last post by:
Hey 2gether! I'm trying to execute a PERL script on the web server when the user presses a button in an ASP.NET Web Application using Visual Basic. The most obvious solution for me seemed to be to use the 'Shell()'-command . This didn't work: Either I get an "File not found" error, or I get no error at all, but the PERL script isn't...
5
1471
by: Jim Simpson | last post by:
I'm working with Perl and trying to write a Perl script that will access sites requiring a "password". Each time I run my code I get the following message: <noscript> <br> <b> We have detected that your browser does not support Javascript or its use is currently disabled. </b> <br> Javascript must be enabled to properly present you several...
37
3526
by: pochartrand | last post by:
Hello, Is there a way to manipulate or at least read the pseudo-class of an element ? I know the style attribute can be accessed and gives the CSS properties for a particular element. However, I can't seem to access the "hover" properties. example :
1
2482
by: Tufty | last post by:
Hi, I have a webpage that lets the user upload an image. This is the posted to a perl script as a form var. The data is stored in SQL 2005 (as the new image object). I now need to get it back out from SQL and display it in an HTML page being generated by perl. I can read the data back in, but can't get it to display. (typically it justs...
1
1632
by: Dave | last post by:
I have "header.html" used by PERL to construct an entire page. Unfortunately, this header page contains no head or body tags; the script generates them. So I am at a loss as to how I can reference 3 external js files to show a js menu in the header page. Nothing I've tried works and I don't want to monkey with the PERL file. If there is a way...
1
1554
by: raman | last post by:
Hi, Kindly, look at the following problem. Objective: To draw a message sequence chart (MSC) from given log file. Input: Generated trace file (eg log.trace) Output: log.trace.html
21
1832
by: TonyV | last post by:
Hi all, I'm trying to use some javascript code in Internet Explorer 6.0 that's being generated by a Perl file. I have a line in my header that looks something like this: <script src="jscode.pl?parm1=foo&parm2=monkey" type="text/javascript" / Just for the sake of simplicity, here's a very simplified version of the Perl code:
2
2827
by: RaviRajhulk | last post by:
I have tried executing executing a batch file from a perl code using system("start c:\\temp\\sample.bat") but it is not executing ,Is there any way to execute batch file from a perl code
22
2865
by: Dan Rumney | last post by:
Hi all, I've been writing Javascript for quite a while now and have, of late, been writing quite a lot of AJAX and AJAX-related code. In the main, my dynamically generated pages are created using Perl on the backend, with Javascript providing limited frontend functionality. As an example, an expanding tree would be fully populated on the...
0
7660
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7761
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5976
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5337
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3457
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1888
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1020
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
709
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.