473,761 Members | 10,057 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 2168
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
4985
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 executed anyway. The strange thing is that I managed to execute a .bat file for example. Why the hell...
5
1484
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 pages on this site, including "Your Portfolio". <br> <br>
37
3582
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
2498
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 says ) when I refere to the perl variable. Has anyone ANY experience / ideas on how to do this?...
1
1648
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 to generate the menu, I'd sure appreciate the code because I'm only slightly better at javascript...
1
1558
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
1864
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
2840
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
2941
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 server-side and then presented to the browser, with Javascript and CSS being used to vary the...
0
9521
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9333
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9765
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8768
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7324
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6599
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5361
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3863
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
3
2733
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.