html通过使用图像源的协议(protocol)相对 URL 来防止安全/不安全错误

有人知道使用 protocol relative URLs 是否有问题吗?用于图像源以防止混合内容安全警告。

例如链接一张图片:

<img src="//domain.com/img.jpg" /> 

代替:

<img src="http://domain.com/img.jpg" /> 
or 
<img src="https//domain.com/img.jpg" /> 

在我的测试中,我没有看到任何迹象表明这是错误的,但我不确定它是否存在会产生问题的边缘情况。

编辑 我看到它在使用 PHP 的 getimagesize 时抛出错误功能。

请您参考如下方法:

在使用协议(protocol)相对 URL 时发现了一个有趣的问题:

ou have to be careful to only use this syntax in pages destined for browsers. If you put it in an email, there will be no base page URL to use in resolving the relative URL. In Outlook at least, this URL will be interpreted as a Windows network file, not what you intended.

来自 here

基本上,只要请求是由浏览器而不是外部电子邮件客户端发出的,就没有正当理由说明这不应该起作用。

更多信息来自 here :

A relative URL without a scheme (http: or https:) is valid, per RTF 3986: Section 4.2. If a client chokes on it, then it's the client's fault because they're not complying with the URI syntax specified in the RFC.

Your example is valid and should work. I've used that relative URL method myself on heavily trafficked sites and have had zero complaints. Also, we test our sites in Firefox, Safari, IE6, IE7 and Opera. These browsers all understand that URL format

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ok060

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值