JavaScript and Dynamic URLs

I am looking to write a very simple JavaScript that fades a set of 4 header logo's in and out in sequence.

The script itself is no problem and I can put it into an external .js file and link that into the site. However, I am wondering what is the best way to go about handling the location of the images themselves.

If I write absolute URLs into the Javascript I assume that they will not get rewritten by the WCM and so if the root path of the site changes, the JS will need editing. But as the Javascript will be writing to the page after the WCM has rendered the content, I assume that using the iMIS URL replacement codes in the Javascript wouldn't work either?

Is there a code that I can put into the javascript to keep the URLs dynamic even if the root path changes? Or have I missed some obvious JavaScript trick that could help here?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

You should be able to use

You should be able to use the variable gWebRoot (defined by iMIS) to represent the current root path, like so:

var imagePath = gWebRoot + '/images/Header.png';

Eric Means
System Architect, ASI

Hi Eric, Many thanks for

Hi Eric,

Many thanks for your response here, I think it might prove useful in the future and probably to anyone else trying to develop image-based JavaScript.

But I have actually realised that I don't even need to use this function for my code though! It makes more sense for me to add all of the images to separate divs prior to the page being rendered, then just fade each div in and out in a cycle to produce the effect.

 

Kieren