在浏览器地址栏,直接输入的URL中,如果未指定协议名,如http、https等,浏览器会自动解析为http
如:输入 //www.baidu.com/,浏览器会自动解析到:http://www.baidu.com/
但在html元素中,解析情况有所不同,浏览器会使用当前页面的协议来解析此类URL
比如,在html代码中,如果当前页面是 http://example.com/,则 //example.com/,会被解析成 http://example.com/
如果当前页面是file:///C:/Users/Administrator/Desktop/test.html,则会解析成 file://example.com/ (注意此处是两个斜线 //)
测试代码:
<img src="//www.baidu.com/img/bdlogo.png">
测试结果:
file协议:
http协议: