Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

anchor <a> + Link to base URL

Tags:

html

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.

like image 823
Adam Avatar asked Sep 28 '11 05:09

Adam


2 Answers

<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.

like image 192
Mark Kramer Avatar answered Sep 20 '22 20:09

Mark Kramer


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.

like image 35
Doozer Blake Avatar answered Sep 20 '22 20:09

Doozer Blake