Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I just have created primitive html page. Here it is: example And here is its markup:

<a href="www.google.com">www.google.com</a>
<br/>
<a href="http://www.google.com">http://www.google.com</a>

As you can see it contains two links. The first one's href doesn't have 'http'-prefix and when I click this link browser redirects me to non-existing page https://fiddle.jshell.net/_display/www.google.com. The second one's href has this prefix and browser produces correct url http://www.google.com/. Is it possible to use hrefs such as www.something.com, without http(s) prefixes?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
350 views
Welcome To Ask or Share your Answers For Others

1 Answer

It's possible, and indeed you're doing it right now. It just doesn't do what you think it does.

Consider what the browser does when you link to this:

href="index.html"

What then would it do when you link to this?:

href="index.com"

Or this?:

href="www.html"

Or?:

href="www.index.com.html"

The browser doesn't know what you meant, it only knows what you told it. Without the prefix, it's going to follow the standard for the current HTTP address. The prefix is what tells it that it needs to start at a new root address entirely.

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

href="//www.google.com"

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...