Href link missing http(s) prefix
P粉329425839
P粉329425839 2023-08-22 21:56:49
0
2
565
<p>I just created a simple HTML page. Here: example This is its markup: </p> <pre class="brush:php;toolbar:false;"><a href="www.google.com">www.google.com</a> <br/> <a href="http://www.google.com">http://www.google.com</a></pre> <p>As you can see, it contains two links. The href of the first link does not have the 'http' prefix, and when I click on this link, the browser redirects me to the non-existent page https://fiddle.jshell.net/_display/www.google. com</code>. The href of the second link has this prefix, and the browser generates the correct URL <code>http://www.google.com/</code>. Is it possible to use href without http(s) prefix like <code>www.something.com</code>? </p>
P粉329425839
P粉329425839

reply all(2)
P粉299174094

You can omit the protocol by using // in front of the path. Here is an example:

<a href="//www.google.com">Google</a>

By using //, you tell the browser that this is actually a new (complete) link, rather than a relative link to the current link.

P粉957723124

It's possible, and you're doing it now. It just won't do what you want.

Think about what the browser will do when you link to this:

href="index.html"

So when you link to this, what does it do? :

href="index.com"

Or this? :

href="www.html"

or? :

href="www.index.com.html"

The browser doesn't know what you mean, it only knows what you tell it. Without the prefix, it will operate according to the standard of the current HTTP address. The prefix tells it to start from a completely new root address.

Please note that you don't need the http: part, you can do this:

href="//www.google.com"

The browser will use the current protocol (http, https, etc.), but // tells it that this is a new root address.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template