为什么网页上的绝对路径可以省略协议? [英] Why can protocol be omitted from absolute paths on a webpage?
问题描述
我最近浏览了一个网站,该网站在选择元素上有一些有趣的样式.我去调查发现这个(为了保护无辜而改名):
I recently ran across a website that had some interesting styling on a select element. I went to investigate and found this (names changed to protect the innocent):
<script type="text/javascript" src="//www.domain.tld/file.js"></script>
尽管 HTTP:
被省略,它仍然有效.放弃协议的目的是什么?
It works despite HTTP:
being omitted. What is the purpose of leaving off the protocol?
推荐答案
它将使用您已经在使用的协议.适用于具有 https
和 http
版本的网站.
It will use the protocol you're already using. Useful for sites with both https
and http
versions.
因此,如果您在 https://www.domain.tld/file.js
上,脚本将是 https://www.domain.tld/file.js代码>.
So if you're on https://www.domain.tld/file.js
the script will be https://www.domain.tld/file.js
.
如果您在 http://www.domain.tld/
上,脚本将是 http://www.domain.tld/file.js
.
If you're on http://www.domain.tld/
the script will be http://www.domain.tld/file.js
.
这篇关于为什么网页上的绝对路径可以省略协议?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!