Discussion Locked

why javascript fails-external .js file?

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

So, this script I'm using on my homepage
(http://danmoriarty.com), to rotate .jpg images,
that only seems to work when it's embedded
in that page's code.

When I try to add it to my external .js file, with
my other javascript code, it fails to work.
Anyone know why?

Here's the code:

also:

and:

I'm trying to learn javascript. Thanks much.

2 replies

by jay eckles

This is sort of a shot in the dark, but the problem may be that you use relative URLs for the images in your Javascript. If the script is embedded in the page, then the relative URLs resolve to what you expect. If the script is included from an external file, the relative URLs may resolve based on the directory where the .js file resides.

I'm not sure if that's correct or not, but I would try using fully qualified URLs in the script and see if that solves the problem.

Good luck.

Jay

by john wilker

I was just working with some JS code and it is in an included file at the same level as the file calling it. Except that the file doing the calling of the include is one level up so the link to the JS needed to be correct based on the main page. I'dwalk through all the links to the images and look at the folder layout, make sure that everything is where the JS file thinks it should be.

J.

This discussion is closed to new replies.