浏览器支持以双斜线开头的 URL [英] Browser support for URLs beginning with double slash

查看:22
本文介绍了浏览器支持以双斜线开头的 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近看到一些没有协议的链接.这似乎并不难理解 - 我认为这是一个好主意,而且非常直观.

I've recently seen a few links used without a protocol. It didn't seem too difficult to understand - I think it's a great idea and pretty intuitive.

对于那些不知道的人,使用像 //example.com/script.js 这样的 URL 将指向 http://example.com/script.js> 或 https://example.com/script.js 取决于 URL 是否源自 httphttps URL.例如,包含来自 https 页面的 http 脚本或图像可能是一个安全问题,因此无需在代码中进行协议检测即可解决此问题.

For those of you unaware, using a URL like //example.com/script.js will point to either http://example.com/script.js or https://example.com/script.js depending on whether or not the URL originates from a http or https URL. Including http scripts or images from a https page can be a security concern, for example, so this solves that without the need for protocol detection in your code.

我的问题是,它有什么样的浏览器/操作系统支持?在生产中使用是否安全?这肯定会让事情变得容易一些.

My question is, what sort of browser/OS support is there for it? Is it safe to use in production? It would certainly make things a bit easier.

简单的例子和​​测试:http://codetester.org/916c6916

Simple example and test: http://codetester.org/916c6916

只是跟进一下,几年来我一直将它用于我公司生产中的广告服务器,许多事情都没有出现问题.

Just a follow up that I've been using this for my company's ad server in production for many things without issue for a couple years now.

推荐答案

此行为是 RFC 1808(第 4 节)已有大约 16 年的历史,因此每个主要浏览器都应该(并且确实)支持这一点.

This behavior was part of RFC 1808 (Section 4) which is about 16 years old, so every major browser should (and does) support this.

遗憾的是,存在 IE7 和 -8 的错误如果在 link@import 上使用与协议相关的 URL,让他们下载资源两次 - 这应该不是一个大问题,但很丑,应该是牢记.

Sadly, there's a bug with IE7 and -8 that will make them download the resources twice if a protocol-relative URL is used on a link or @import - which shouldn't be a big problem, but is ugly and should be kept in mind.

这篇关于浏览器支持以双斜线开头的 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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