Get the URL of the current page:
let url = location.href;
Try it Yourself »
Set the URL of the current page:
location.href = "https://www.91xjr.com";
Try it Yourself »
More examples below.
The location.href
property sets or returns the entire URL of the current page.
Return the href property:
location.href
Set the href property:
location.href =
URL
Parameter | Description |
URL | An absolute URL like: http://www.example.com/default.htm A relative URL like default.htm An anchor URL like location.href="#top" A new protocol like: ftp://someftpserver.com mailto:someone@example.com file://host/path/example.txt |
Type | Description |
A string | The full URL of the page, including the protocol (like https://). |
Set the href value to point to an email address (will open and create a new email message):
location.href = "mailto:someone@example.com";
Try it Yourself »
location.href
is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!