SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist hantaah's Avatar
    Join Date
    Jul 2011
    Location
    Birmingham, Uk
    Posts
    562
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    How to correctly use file paths?

    I've always shied away from this and used the full path but how is it correctly done?

    I have a directory with this path: http://localhost/JQuery/JQueryHello.html
    and in this file i want to point to this: http://localhost/jquery/JQuery-HW/jquery-1.9.1.min.js

    so do I put <script src=”/jquery-1.4.2.min.js” type=”text/javascript”></script>

    or

    <script src=”JQuery-HW/jquery-1.4.2.min.js” type=”text/javascript”></script>

    or what exactly?

  2. #2
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Depends were your file is. If its in the same folder then you can use a relative path and link to just the file name file.php. If the file is in another folder then to link to it you'd say folder/file.php. If you need to come out of a folder and then back into the folder were the file is you'd say. ../folder/file.php. Or you can say start from the root (not the folder) by saying /folder/file.php.

  3. #3
    SitePoint Evangelist hantaah's Avatar
    Join Date
    Jul 2011
    Location
    Birmingham, Uk
    Posts
    562
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by EricWatson View Post
    Depends were your file is. If its in the same folder then you can use a relative path and link to just the file name file.php. If the file is in another folder then to link to it you'd say folder/file.php. If you need to come out of a folder and then back into the folder were the file is you'd say. ../folder/file.php. Or you can say start from the root (not the folder) by saying /folder/file.php.

  4. #4
    SitePoint Evangelist hantaah's Avatar
    Join Date
    Jul 2011
    Location
    Birmingham, Uk
    Posts
    562
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    I see, so it's just a matter of working backwards and leaving out what you don't need?

  5. #5
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,177
    Mentioned
    454 Post(s)
    Tagged
    8 Thread(s)
    The safest (and easiest way) is to provide a path relative to the root folder. That way, the same path works no matter where it's placed in the site. If you want a link to the jQeury file on each page, for example, this is the way to go.

    So let's say you have a folder in your site's root folder (where your home page is) called /scripts/, and in there is your jQuery library script, jquery.min.js or whatever. You can link to that file from anywhere in your site with:

    Code:
    <script src="/scripts/jquery.min.js" type=”text/javascript”></script>
    The only caveat is that these root relative links (with the slash at the front) don't work on your desktop version, unless you have a virtual server environment set up.

  6. #6
    SitePoint Evangelist hantaah's Avatar
    Join Date
    Jul 2011
    Location
    Birmingham, Uk
    Posts
    562
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    yes I'm running wamp and xampp. Thanks for the info, will be using it from now


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •