Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

problem with including external javascript file with start_html

by pitbull3000 (Beadle)
on Sep 04, 2001 at 14:38 UTC ( [id://110003]=perlquestion: print w/replies, xml ) Need Help??

pitbull3000 has asked for the wisdom of the Perl Monks concerning the following question:

i include a external javascript file (ua.js) with
print $query->start_html(-title=>'Umgebungsvariablen auslesen', -script=>{-src=>'ua.js'});
in this javascript are some routines which are processed. if i write some static html and include this js file, all is well done, and i can access some of the variables defined in the ua.js file. but when creating the page on the fly with cgi, the routines are not processed and i couldnīt access the specific variables out of the js file. again if i include the javascript code into the perl script in some variable, and print this variable all goes fine. but i dont want to include all this js stuff into my perl code, also i dont want to open the js file during runtime of the script, and read the file into a variable... any ideas how to handle this thanks pitbull3000

Replies are listed 'Best First'.
Re: problem with including external javascript file with start_html
by Masem (Monsignor) on Sep 04, 2001 at 15:33 UTC
    One thing you should try to do when you have problems with what CGI puts out and what static HTML puts out is to save the output of the CGI as given to your browser, and do a hand comparison of both scripts to see what's present and what's missing in both. The CGI.pm documentation does notes that it will try to format the output to make certain browsers happy, and this might be causing your problem which will only show up in the actual output.

    -----------------------------------------------------
    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
    It's not what you know, but knowing how to find it if you don't know that's important

Re: problem with including external javascript file with start_html
by George_Sherston (Vicar) on Sep 04, 2001 at 15:24 UTC
    I've just been using the same code for my own project, and what you have there works for me, so I can't suggest a positive solution. I know this doesn't help! Does the html that your cgi creates on the fly look the same as the static html that works? Or
    (1) Do you need to specifiy -language=>'JavaScript'? ... answer probably not, as in the current version of CGI.pm that is the default anyway.
    (2) Do you need -onload=>'your.function()' to run the js?

    Apart from that I can't think of anything helpful except to repeat that what you're trying to do does work, so there is a solution. Only I don't know it!

    § George Sherston
Re: problem with including external javascript file with start_html
by Corion (Patriarch) on Sep 04, 2001 at 15:30 UTC

    My solution to this problem is more like a hammer, I output something like this :

    print qq(<script src="lib.js"></script>)

    I admit that I haven't used CGI.pms ways of generating stuff in the HTML header much to be of help in that case.

      just stick to your suggestion, unfortunately i couldnt use the print start_html then, or i just put my script outside the head.... thanks guys
        Dont include your javascript file cgi-bin directory instead use any other folder outside of cgi-bin.
        include full path like http://localhost/perl_js/main.js
Re: problem with including external javascript file with start_html
by wardk (Deacon) on Sep 04, 2001 at 18:31 UTC
    Is this an issue with location?

    try hard-coding the full path to the file (from the web perspective, not filesystem).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2024-04-18 07:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found