Click to See Complete Forum and Search --> : Relative location of source in template


mlibkind
12-09-2007, 06:35 PM
I use the following script to write a random banner. Don't worry about the details.

<script language="JavaScript" type="text/javascript" src="../assets/scripts/pick_banner.js"></script>
<script language="javascript" type="text/javascript">
var returned_info=pick_banner();
var new_banner=returned_info[0];
var new_link=returned_info[1];
document.write("<a href='" +new_link+ "'target='_blank'><img src='../assets/banners/" +new_banner+ "' alt='Banner' /></a>");
</script>

I have used it successfully in several web pages. In each case I adjust the relative position of the source files, e.g. change ../ to ../../../ where necessary.

Now I want to use it in a template. I test the template and it looks fine. I then assign the template to a web page. The relative location of the javascript file changes from ../ to ../../ which is necessary. However, the relative location of the image is not changed and therefore the browser can't find the image. Instead the alt text is displayed and the link works.

Why does one relative location change and the other doesn't when the template is applied??? Is there a fix?

Please help if you can. I'm truly baffled.

Marcus

Centauri
12-09-2007, 08:02 PM
The document.write text is simply that - a text string to be written dynamically to the web page, and is not treated as a link in the source code.

I do wonder, though, why do you need differing relative paths ? If all the html files were in the same folder, path changes would not be needed. The other alternative would be to write the path without the leading ".." as long as the "assets" folder is located in the site root.

mlibkind
12-09-2007, 09:28 PM
Your answer is very clear and simple. I should have figured it out.

I have hundreds of pages and the template may be used in different directories. It would be unwieldly if all the files were in one folder. But your other suggestion, addressing the image absolutely, will solve the problem.

Thanks very much.

Marcus