How do I put a hyperlink to "two levels above in the directory tree"?
Asked Answered
L

6

24

I am trying to code my Home button. Is there a way to just climb back up the file structure, instead of using the absolute path like I have below.

I have a file index.html that I have at C:\Users\Randy\Documents\XML\

Heres my code:

<a id="my-family" href="C:\Users\Randy\Documents\XML\index.html">Home</a> 

Heres where I am trying to come from: C:\Users\Randy\Documents\XML\project\xml

Lamination answered 13/8, 2011 at 16:23 Comment(0)
R
27

You can use ../index.html to refer to index.html in the parent directory.

Rival answered 13/8, 2011 at 16:30 Comment(3)
Thanks but that didnt work. I get page cannot be displayed, and my guess is it still doesnt find the index.htmlLamination
I was trying to go back up 2 directorys so I needed ../../ Thanks for your help.Lamination
If you are at C:\Users\Randy\Documents\XML\project\xml and want to go to C:\Users\Randy\Documents\XML\index.html you of course need to go up two levels: ..\..\index.html.Rival
M
43

to go two level up use "../../" and your normal url from two level up folder.

"../" in the path is used to go one level up. But, it can be used for more times, to go more levels up.

an example:

| HOME <br> 
+- image.jpg<br> 
|_
  |
  +- CONFIG<br>  
     |
     + PICTURE_CONFIG
       | 
       +- myfile.html

myfile.html contains:

<img src="../../image.jpg" />

the second"../" goes from PICTURE_CONFIG to CONFIG folder
the first "../"goes from CONFIG to HOME folder
"image.jpg" searches in HOME folder for the file "image.jpg"

Mcdermott answered 10/8, 2015 at 19:44 Comment(1)
Thank you for posting an answer to this question! It would be helpful if you provide a bit more context for your answer though!Fransis
R
27

You can use ../index.html to refer to index.html in the parent directory.

Rival answered 13/8, 2011 at 16:30 Comment(3)
Thanks but that didnt work. I get page cannot be displayed, and my guess is it still doesnt find the index.htmlLamination
I was trying to go back up 2 directorys so I needed ../../ Thanks for your help.Lamination
If you are at C:\Users\Randy\Documents\XML\project\xml and want to go to C:\Users\Randy\Documents\XML\index.html you of course need to go up two levels: ..\..\index.html.Rival
S
4

On Windows OS, the forward-slash (/) wasn't working, so I switched to back-slash (\) and that fixed it. For example, try using the following:

"..\..\index.html"
Sturdivant answered 9/4, 2020 at 15:25 Comment(0)
P
2

I'm not sure exactly what you're asking, but in relative paths, ../ is 'up one level'.

So, ../index.html would take you to the index of the next directory up. Hope that helps.

Passably answered 13/8, 2011 at 16:34 Comment(0)
C
2
  1. <img src="picture.jpg"> WHEN picture.jpg is located in the same folder as the current page

  2. <img src="images/picture.jpg"> WHEN picture.jpg is located in the images folder located in the current folder

  3. <img src="/images/picture.jpg"> WHEN picture.jpg is located in the images folder located at the root of the current web

  4. <img src="../picture.jpg"> WHEN picture.jpg is located in the folder one level up from the current folder

    1. <img src="../../picture.jpg"> WHEN picture.jpg is located in the folder two levels up from the current folder

Hope this example help :)

Source: https://www.w3schools.com/html/html_filepaths.asp

Conversationalist answered 9/6, 2017 at 14:17 Comment(0)
A
-2

In IIS10 below is my observation and both works fine:

single Dot will take you one folder above
img src="./images/picture.jpg"

Double Dot will take you two folders above
img src="../images/picture.jpg"

Autoclave answered 10/3, 2021 at 12:8 Comment(4)
This question was asked almost 10 years ago, and had been answered by many people, and your answer brings nothing new to this discussion. Could you perhaps edit to provide new information? If you can't provide any, this answer is pointless.Emmanuel
I had faced this issue myself and got the solution myself too, none of the solutions above worked for me except mine, if you had really went thru all the solutions, you would have realized that my solution is different than any other solutions above. Even if the question was old I posted an answer so it might help atleast one person, I just cant help when your whole intention is just to down vote an answer!!!Autoclave
From what I can read, your answer is the same as https://mcmap.net/q/542766/-how-do-i-put-a-hyperlink-to-quot-two-levels-above-in-the-directory-tree-quot , just lower qualityEmmanuel
Also confusing, as "single Dot will take you one folder above" is incorrect - a single dot refers to the current folder.Emmanuel

© 2022 - 2024 — McMap. All rights reserved.