tags:

views:

435

answers:

6

How can I link to html pages if they are in same or different folders without writing full path?

+1  A: 

use the relative path

main page might be: /index.html

secondary page: /otherFolder/otherpage.html

link would be like so:

<a href="/otherFolder/otherpage.html">otherpage</a>
Chris Ballance
It's that just for asp.net? And even then, you need a server side control (runat="server").
Kobi
You are correct, I've been in the ASP.NET world too long :-)
Chris Ballance
+1  A: 

You can go up a folder in the hierarchy by using

../

So to get to folder /webroot/site/pages/folder2/mypage.htm from /webroot/site/pages/folder1/myotherpage.htm your link would look like this:

<a href="../folder2/mypage.htm">Link to My Page</a>
Robert Harvey
+5  A: 

Within the same folder, just use the file name:

<a href="thefile.html">my link</a>

Within a super-directory:

<a href="../thefile.html">my link</a>

Within a sub-directory:

<a href="subdir/thefile.html">my link</a>
AgileJon
Add to that the addition of joeylange and you've got yourself the answer. :)
Kriem
+2  A: 

In addition, if you want to refer to the root directory, you can use:

/

Which will refer to the root. So, let's say we're in a file that's nested within a few levels of folders and you want to go back to the main index.html:

<a href="/index.html">My Index Page</a>

Robert is spot-on with further relative path explanations.

joeylange
A: 

I would caution you: if you are using absolute paths, then your application cannot be installed in a "subdirectory" of the server!

eg, http://yourserver.com/yourapp may work, but http://myserver.com/apps/yourapp will not!

Here Be Wolves
A: 

Also, this will go up a directory and then back down to another subfolder.

<a href = "../subfolder/page.html">link</a>

To go up multiple directories you can do this.

<a href = "../../page.html">link</a>

To go the root, I use this

<a href = "~/page.html">link</a>
swagers