If I'm on a page like
http://localhost/balibar.co/?dating=dating-articles-and-information
and I want to have anchor that links to the base URL being
http://localhost/balibar.co
Is there a way to do this without hard coding the URL?
I've tried:
<a href="/"></a>
<a href="#"></a>
will have a few domains use this page so I don't want to hard code the domain name if possible.
<head>
<base href="http://www.google.com" />
</head>
<body>
<a href="">Google?</a>
</body>
That link will now go to google.com
Here is the proof:
http://jsfiddle.net/3wXCJ/
You use HTML's <base>
tag to specify the base url for all elements that use the href
attribute. Now, any tag with an href
or src
attribute that is empty, it will automatically go to the url you specified in the base tag by default.
Assuming the page can load fine as http://localhost/balibar.co/ then a relative path with a single dot (.) will take you to it <a href="./"></a>
I believe you can also use a single dot by itself without the slash <a href="."></a>
The single dot (.) in the relative path represents the current directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With