问题描述
在页面上避免不安全内容警告的一个很好的技巧可能是 http
或 https
是引用所有代码中的脚本或资产使用//,它将使用当前页面协议而不是指定的协议。
A nice trick to avoid insecure content warnings on pages that could be either http
or https
is to reference all scripts or assets in the code using "//" which will use the current page protocol instead of a specified one.
如果在前面直接将 //
的URL输入浏览器URL框,是否有默认值浏览器会选择哪些行为?是/应该默认为 http
或 https
,还是一组规则来测试和选择一个而不是另一个?
If one enters a URL with //
in the front directly into a browser URL box, is there a default behavior the browser will pick? Would/should it default to http
or https
, or some set of rules to test and pick one over the other?
推荐答案
网络路径参考(例如, // example.com/)是。要解析相对引用,。
A network-path reference (e.g.,
//example.com/
) is a relative reference. For resolving a relative reference, a base URI is necessary.
当在浏览器的地址栏中输入网络路径引用时,前三种方式不能建立这样的基本URI,所以第四种方式,,适用:
When entering a network-path reference into a browser’s address bar, no such base URI can be established with the first three ways, so the fourth way, 5.1.4. Default Base URI, applies:
换句话说,它取决于每个浏览器。
In other words, it’s up to each browser.
如果浏览器只支持
http
和 https
,它可能会选择在用户输入类似www.example.com时使用的相同方案,因此可能 http
(参见)。但是许多浏览器支持更多方案。
If a browser would only support
http
and https
, it would likely choose the same scheme that gets used when users enter something like "www.example.com", so probably http
(see Suffix Reference). But many browsers support more schemes.
例如,在我的系统上,请求
scheme: // example.com/test
使用 file file:////example.com/test
(Firefox), file :///example.com/test
(Chromium)。
For example, on my system, requesting //example.com/test
resolves to a URI using the file
scheme: file:////example.com/test
(Firefox), file:///example.com/test
(Chromium).
这篇关于以“//”开头的URL的预期行为是什么?什么时候没有从现有页面链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!