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

相关推荐
mCell2 小时前
Lua 编程入门:从基础语法到元表
javascript·算法·lua
伟大的兔神3 小时前
我做了一个本地优先的 AI 图片工作台:Loomora v1.0.0 正式发布
前端·javascript·vue.js
三言老师3 小时前
K8s集群运行时自动化运维全覆盖落地实操(下)
linux·运维·服务器·网络
Super 含3 小时前
Android 启动优化(五):线程、GC 与 IO 为什么会拖慢启动?
java·服务器·数据库
土星云SaturnCloud5 小时前
产线SOP动作级AI监管方案:土星云SE110S-WC8赋能合规识别、预警与效率分析
大数据·服务器·人工智能·ai·边缘计算
fangzhanpeng1685 小时前
(前端)2.js变量作用域样例
开发语言·前端·javascript
躺不平的理查德5 小时前
嵌入式 Linux 系统移植与 SD 卡量产镜像制作
linux·运维·服务器
码艺-Alimjan7 小时前
Vue项目源码备份最佳实践:无视node_modules,打包体积仅2MB
前端·javascript·vue.js
xixiaoyunya9 小时前
JavaScript 异步编程全解析:从回调地狱到 async/await 的演进之路
开发语言·javascript·ecmascript