How to link one html page to another one in anothe

2020-03-31 07:06发布

问题:

Can't link the page "index2.html"0 from the "rock-paper-scissors-game2" folder to "index.html" in the "digital-clock" folder. Not sure if the code is wrong or something else.

I'm using Atom by the way, and I don't know what else to try because the code for the link looks correct.

<a href="rock-paper-scissors-game2/index2.html"> Game </a>

And when I run it in chrome it gives the file not found error.

Your file was not found It may have been moved or deleted. ERR_FILE_NOT_FOUND

回答1:

To link to another file WITHIN your web site structure, you should use relative references. Relative means, relative to the currently loaded resource.

To access something in the same folder: Just use the file name:

<a href="file.html">Click Me<a>

To access something in a child folder: Start with the child folder name, a slash, and the file name:

<a href="childFolder/file.html">Click Me<a>

To access something starting at the root of your site, begin the path with a forward-slash:

<a href="/pathToFile">Click Me<a>

To access something in a parent folder, start with two dots and a forward-slash:

<a href="../file.html">Click Me<a>

To access something that is in a combination of the above, like a sibling folder, you need to go up to the parent and then down to the correct child:

<a href="../digital-clock/index2.html">Click Me<a>

As an initial test to make sure the file exists, temporarially place it in the same folder as the current page and see if the first example I showed works. If not, you've got a different issue than you think.

Next, you mention that index2.html is in the digital-clock folder, but you didn't reference that folder in your link, so make sure to include that. But, depending on where that folder is will dictate which method I've shown above you need to use.



回答2:

This should work <a href="../rock-paper-scissors-game2/index2.html">Game</a>