Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Writing a full path without the domain

Reply
Thread Tools

Writing a full path without the domain

 
 
Nathan Sokalski
Guest
Posts: n/a
 
      05-02-2005
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.
--
Nathan Sokalski

http://www.nathansokalski.com/


 
Reply With Quote
 
 
 
 
Evertjan.
Guest
Posts: n/a
 
      05-02-2005
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";


--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

 
Reply With Quote
 
 
 
 
Lee
Guest
Posts: n/a
 
      05-02-2005
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";

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Making a server on one domain the domain controller of a new domain Limited Wisdom MCSA 7 09-13-2006 02:18 AM



Advertisments