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粉2991740942023-08-23 09:10:30
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粉9577231242023-08-23 00:13:24
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.