使用前导双斜杠继承 URL 中的协议有什么缺点吗?即 src="//domain.com"; [英] Is there any downside for using a leading double slash to inherit the protocol in a URL? i.e. src="//domain.com"

查看:21
本文介绍了使用前导双斜杠继承 URL 中的协议有什么缺点吗?即 src="//domain.com";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从外部域加载图像的样式表,我需要它根据当前 URL 从安全订单页面的 https://和其他页面的 http://加载.我发现以双斜线开头的 URL 继承了当前协议.所有浏览器都支持这种技术吗?

I have a stylesheet that loads images from an external domain and I need it to load from https:// from secure order pages and http:// from other pages, based on the current URL. I found that starting the URL with a double slash inherits the current protocol. Do all browsers support this technique?

html 例如:

<img src="//cdn.domain.com/logo.png" />

css 示例:

.class { background: url(//cdn.domain.com/logo.png); }

推荐答案

如果浏览器支持 RFC 1808 第 4 节RFC 2396 第 5.2 节RFC 3986 Section 5.2,那么它确实会使用以//"开头的引用的页面 URL 方案.

If the browser supports RFC 1808 Section 4, RFC 2396 Section 5.2, or RFC 3986 Section 5.2, then it will indeed use the page URL's scheme for references that begin with "//".

这篇关于使用前导双斜杠继承 URL 中的协议有什么缺点吗?即 src="//domain.com";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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