为什么锚标记的href值需要http://预先写入URL? [英] Why does an anchor tag's href values need http:// preprended to the URL?

查看:138
本文介绍了为什么锚标记的href值需要http://预先写入URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < a href =www.stackoverflow.comtarget =_ blank>点击此处< / a> 

点击网站HTML页面的上述链接会尝试让用户

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

下面的工作正常

 < a href =http:/ /www.stackoverflow.comtarget =_ blank>点击此处< / a> 

这种行为的基本原理是什么?



基本上,如果没有 / 或协议,假设没有协议的href中的任何文本被假定为相对路径。


<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?

解决方案

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.

这篇关于为什么锚标记的href值需要http://预先写入URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆