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

前端之家收集整理的这篇文章主要介绍了html – 通过使用图像源的协议相对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" />

在我的测试中,我没有看到任何建议这是错误的,但我不知道如果它有边缘的情况下会造成问题.

编辑我看到它使用PHPgetimagesize功能时丢失错误.

解决方法

找到一个有趣的getcha来使用协议相对URL:

You 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

原文链接:https://www.f2er.com/html/230605.html

猜你在找的HTML相关文章