javascript - 没有协议(protocol)编写的 URL 的规则是什么?

标签 javascript css html

<分区>

我不记得我是从什么时候开始看到没有协议(protocol)的 URL。

<script src="//jquery.com/jquery.js"></script>

...但我立刻明白了。当我们不知道协议(protocol)是什么时,不必列出协议(protocol)真是太好了。很遗憾,我不知道这里的规则是什么。

这样也可以吗?

<link href="//stylesheet.com/stylesheet.css" />

这个呢?

/* stylesheet.css */
@import url(//fonts.googleapis.com/css?family=Questrial);

我不仅要在这里寻找答案,还要寻找权威指南的出处。而且我什至不知道这种技术叫什么。

我不知道浏览器支持什么,或者在浏览器不支持的情况下会发生什么。

感谢您的帮助!

更新

我一直在寻找的很多答案都可以在 this question 上找到.

最佳答案

这些称为协议(protocol)相关 URI。

解析规则详见RFC 3986 .

4.2. Relative Reference

A relative reference takes advantage of the hierarchical syntax (Section 1.2.3) to express a URI reference relative to the name space of another hierarchical URI.

  relative-ref  = relative-part [ "?" query ] [ "#" fragment ]

  relative-part = "//" authority path-abempty
                / path-absolute
                / path-noscheme
                / path-empty

第 5.4 节有示例。

5.4. Reference Resolution Examples

Within a representation with a well defined base URI of

  http://a/b/c/d;p?q

a relative reference is transformed to its target URI as follows.

  ...
  "//g"           =  "http://g"
  ...

关于javascript - 没有协议(protocol)编写的 URL 的规则是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27712453/

上一篇:html - 自定义CSS按钮div问题

下一篇:jquery - 使用输入 slider 更改文本颜色的颜色

相关文章:

html - 详细信息和摘要 : delete or hide "arrow"

html - Bootstrap 3 下拉列表显示在 Chrome Inspector 中,但不显示在浏览器中

javascript - 如何动态绑定(bind) Angular 图表的数据

javascript - 什么是 prototype.constructor 及其在原型(prototype)链中的作用 - Javascript

jquery - 使用 NicEditor 调整窗口大小

JQuery Sortable 重叠问题

php - 显示来自 blob 字段 php 的相同图像

javascript - 使用 js 加载 css 样式表来更新已渲染网页的样式

JavaScript - 设置函数返回基于 1 或 2 个选定标签的所有项目(无 jQUERY)

html - Bootstrap : Dropdown on top of accordion