當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Node.js URL.origin用法及代碼示例

url.origin

曆史
版本變化
v15.0.0

方案"gopher" 不再特殊,url.origin 現在為它返回'null'

獲取 URL 源的隻讀序列化。

const myURL = new URL('https://example.org/foo/bar?baz');
console.log(myURL.origin);
// Prints https://example.org
const idnURL = new URL('https://測試');
console.log(idnURL.origin);
// Prints https://xn--g6w251d

console.log(idnURL.hostname);
// Prints xn--g6w251d

相關用法


注:本文由純淨天空篩選整理自nodejs.org大神的英文原創作品 URL.origin。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。