-1

consider the following code:

<a id="alink" href="http://google.com">google</a>

This is a fairly basic link tag. At the top of my html page I have:

<base href="//localhost/website/" />

This creates a problem, when i click my link it brings me to:

//localhost/website/http://google.com

I do not want this, I want it to bring me to a completely different site(google.com for example). How can I fix this problem?

Jack
  • 23
  • 1
  • 4
  • When you set // you are telling the browser that the URL should be relative to the current page. See this for further info: http://stackoverflow.com/questions/4071117/uri-starting-with-two-slashes-how-do-they-behave – Henrique M. Sep 24 '16 at 17:34

2 Answers2

1

try this one.

<base href="http://localhost/website/" />

on localhost no need for directory or double slashes // !=link.

0

The effect of the base tag is global to the document, and the only way to override the effect of  is to use absolute URLs.

You can use window.location in JavaScript to get the URL of the page itself, in case the document was retrieved via HTTP. And you could use it to construct absolute URLs.

But It is better to use server-side technologies that let you construct addresses from one or more base addresses. So quite possibly the best approach is to get rid of the tag.

Vivek Kumar
  • 360
  • 1
  • 7
  • 16