Writing a full path without the domain

  • Thread starter Nathan Sokalski
  • Start date
N

Nathan Sokalski

I have a rollover script that I plan to use for many of my pages. When I
preload the images, the directories must be relevant to the location of the
HTML file that uses the script, which will not always be the same. Because
of this, I figured the only way to place the script in an external file and
still have it work was to use full path names including everything after the
domain. For example, if my image was located in
http://www.mydomain.com/images/image1.gif, I would like to store the
directory as something like /images/image1.gif so that I have the entire
path entered but do not have to modify it when my domain changes. However,
Javascript does not seem to like the format I showed above. What can I do to
achieve this? The lines of code where this will be used currently look like
the following:

navrollovers[0]=new Image();
navrollovers[0].src="images/button_home_white.gif";

As you can see, the second line will not work for HTML files in directories
other than the root. What should the code look like? Thanks.
 
E

Evertjan.

Nathan Sokalski wrote on 02 mei 2005 in comp.lang.javascript:
navrollovers[0]=new Image();
navrollovers[0].src="images/button_home_white.gif";

As you can see, the second line will not work for HTML files in
directories other than the root. What should the code look like?
Thanks.

navrollovers[0].src="/images/button_home_white.gif";
 
L

Lee

Nathan Sokalski said:
I have a rollover script that I plan to use for many of my pages. When I
preload the images, the directories must be relevant to the location of the
HTML file that uses the script, which will not always be the same. Because
of this, I figured the only way to place the script in an external file and
still have it work was to use full path names including everything after the
domain. For example, if my image was located in
http://www.mydomain.com/images/image1.gif, I would like to store the
directory as something like /images/image1.gif so that I have the entire
path entered but do not have to modify it when my domain changes. However,
Javascript does not seem to like the format I showed above. What can I do to
achieve this? The lines of code where this will be used currently look like
the following:

navrollovers[0]=new Image();
navrollovers[0].src="images/button_home_white.gif";


navrollovers[0].src="/images/button_home_white.gif";

or, fully (for no good reason):

navrollovers[0].src="http://"+
location.hostname+
"/images/button_home_white.gif";
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top