i have a question about how relative links work
i went to a particular website and saw that i was 2 subdirectories deep, that is i was at www.blabla.com/bla/bla/page
then i looked at the source code of the page and saw that the source of an image was src='/images/soso.png'
so one would expect that the full address of this image was
www.blabla.com/bla/bla/images/soso.png
but it wasn't!!! it was at
www.blabla.com/images/soso.png
this is not how these links usually work.
somehow, the browser knew to use the root directory, instead of the current subdirectory of the page. how did it know?
Strange relative links
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Strange relative links
A relative link in html does not begin with a slash. It represents the root directory. So basically,
src='/images/soso.png' is the same as src='http://domain.com/images/soso.png'
Now.. if there was not the leading slash, which makes it relative, it would have behaved as you described.
src='/images/soso.png' is the same as src='http://domain.com/images/soso.png'
Now.. if there was not the leading slash, which makes it relative, it would have behaved as you described.
-
chopficaro
- Forum Commoner
- Posts: 68
- Joined: Fri Jan 01, 2010 12:56 am
Re: Strange relative links
r u kidding me? danm i feel like i should have known that
thank you
thank you
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Strange relative links
.. unless of course you are using the <base> tag, which sets the root directory path.
Glad you learned something new, and your certainly welcome.
Glad you learned something new, and your certainly welcome.