使用前导双斜杠来继承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"

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

问题描述

我有一个样式表,可以从外部域加载图像,我需要它从https://从安全订单页面加载,http://从其他页面加载,基于当前URL。我发现使用双斜杠启动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 ex:

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

css ex:

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


推荐答案

如果浏览器支持 RFC 1808第4节 RFC 2396第5.2节,或 RFC 3986第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 =&quot; // domain.com&quot;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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