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

Categories

0 votes
921 views
in Technique[技术] by (71.8m points)

html - Why does an anchor tag's href values need http:// preprended to the URL?

<a href="www.stackoverflow.com" target="_blank">click here</a>

Clicking the above link on a site's HTML page would try to take the user to

<site>/index.html/www.stackoverflow.com

Where as following works fine

<a href="http://www.stackoverflow.com" target="_blank">click here</a>

What is the rationale for this behavior?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

There are several protocols: HTTP, HTTPS, FILE, SSH, SSL, FTP. In addition, as Jeremy mentioned, it's quite possible you may have a file on your server with the exact name of the text you're entering in the HREF.

Basically, any text in the href without a protocol is assumed to be a relative path if there is no / or protocol.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...