特别计划


【Special schemes】

WHATWG URL 标准 将少数几种 URL 协议方案视为在解析和序列化方面具有特殊性的协议。当使用这些特殊协议之一解析 URL 时,url.protocol 属性可能会被更改为另一种特殊协议,但不能更改为非特殊协议,反之亦然。

【The WHATWG URL Standard considers a handful of URL protocol schemes to be special in terms of how they are parsed and serialized. When a URL is parsed using one of these special protocols, the url.protocol property may be changed to another special protocol but cannot be changed to a non-special protocol, and vice versa.】

例如,将 http 改为 https 是可行的:

【For instance, changing from http to https works:】

const u = new URL('http://example.org');
u.protocol = 'https';
console.log(u.href);
// https://example.org/ 

然而,从 http 改为假想的 fish 协议并不会有什么不同,因为这个新协议并不特殊。

【However, changing from http to a hypothetical fish protocol does not because the new protocol is not special.】

const u = new URL('http://example.org');
u.protocol = 'fish';
console.log(u.href);
// http://example.org/ 

同样地,从非专用协议更改为专用协议也是不允许的:

【Likewise, changing from a non-special protocol to a special protocol is also not permitted:】

const u = new URL('fish://example.org');
u.protocol = 'http';
console.log(u.href);
// fish://example.org 

根据 WHATWG URL 标准,特殊协议方案包括 ftpfilehttphttpswswss

【According to the WHATWG URL Standard, special protocol schemes are ftp, file, http, https, ws, and wss.】