Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

problem with including external javascript file with start_html

by pitbull3000 (Beadle)
on Sep 04, 2001 at 14:38 UTC ( #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

Comment on problem with including external javascript file with start_html
Download Code
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 (Pope) 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 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 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
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? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2014-07-24 09:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (158 votes), past polls