Get the protocol, hostname and port number of the URL:
let origin = location.origin;
Try it Yourself »
The origin
property returns the protocol, hostname and port number of a URL.
The origin
property is read-only.
If the port number is not in the URL, or if it is a default port like 80 (Http), or 443 (https), some browsers will not display the port number.
location.origin
Type | Description |
A string | The protocol (including ://), the domain name (or IP address) and port number (including the colon sign (:) of the URL. For URL's using the "file:" protocol, the return value differs between browsers. |
location.origin
is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!