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

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

例如链接一张图片:

html 复制代码
<img src="//domain.com/img.jpg" /> 

代替:

html 复制代码
<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

相关推荐
码农刚子4 分钟前
ASP.NET Core Blazor简介和快速入门 二(组件基础)
javascript·后端
Andya_net11 分钟前
Java | 基于redis实现分布式批量设置各个数据中心的服务器配置方案设计和代码实践
java·服务器·分布式
博语小屋19 分钟前
Linux进程信号(壹)_产生信号
linux·运维·服务器
元亓亓亓27 分钟前
考研408--计算机网络--day1-概念&组成功能&三种交换技术&分类
服务器·计算机网络·考研
我是日安39 分钟前
从零到一打造 Vue3 响应式系统 Day 27 - toRef、toRefs、ProxyRef、unref
前端·javascript·vue.js
不如喫茶去1 小时前
VUE查询-历史记录功能
前端·javascript·vue.js
养海绵宝宝的小蜗1 小时前
Linux 例行性工作任务(定时任务)知识点总结
linux·运维·服务器
一枚前端小能手1 小时前
「周更第8期」实用JS库推荐:decimal.j
前端·javascript
乌萨奇也要立志学C++1 小时前
【Linux】基础IO(二)深入理解“一切皆文件” 与缓冲区机制:从原理到简易 libc 实现
linux·运维·服务器
Tech_Lin1 小时前
JavaScript Date时间对象的常用操作方法总结
前端·javascript