Writing a full path without the domain

Discussion in 'Javascript' started by Nathan Sokalski, May 2, 2005.

  1. 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/
    Nathan Sokalski, May 2, 2005
    #1
    1. Advertising

  2. Nathan Sokalski

    Evertjan. Guest

    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)
    Evertjan., May 2, 2005
    #2
    1. Advertising

  3. Nathan Sokalski

    Lee Guest

    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";
    Lee, May 2, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Samuel R. Neff
    Replies:
    2
    Views:
    579
    bradley
    Jun 10, 2005
  2. Nikron
    Replies:
    6
    Views:
    17,281
    Mark Rae
    May 31, 2006
  3. dude
    Replies:
    5
    Views:
    1,681
    Jussi Piitulainen
    Mar 17, 2011
  4. Replies:
    1
    Views:
    163
    Ken Bloom
    May 28, 2007
  5. Chem Leakhina
    Replies:
    2
    Views:
    128
    Robert Klemme
    Jun 23, 2009
Loading...

Share This Page