url.href
获取和设置序列化的网址。
🌐 Gets and sets the serialized URL.
const myURL = new URL('https://example.org/foo');
console.log(myURL.href);
// Prints https://example.org/foo
myURL.href = 'https://example.com/bar';
console.log(myURL.href);
// Prints https://example.com/bar 获取 href 属性的值等同于调用 url.toString()。
🌐 Getting the value of the href property is equivalent to calling
url.toString().
将此属性的值设置为新值等同于使用 new URL(value) 创建一个新的 URL 对象。每个 URL 对象的属性都会被修改。
🌐 Setting the value of this property to a new value is equivalent to creating a
new URL object using new URL(value). Each of the URL
object's properties will be modified.
如果赋给 href 属性的值不是有效的 URL,将会抛出 TypeError。
🌐 If the value assigned to the href property is not a valid URL, a TypeError
will be thrown.