The Location
object represents the URL of the object it is linked to, and any modifications made are reflected in the associated object. Both the Document
and Window
objects have a link to Location
, which can be accessed through document.location
and window.location
, respectively.
location.href
: Contains aDOMString
of the entire URL, whereDOMString
is aUTF-16
string that directly maps to aString
in JavaScript.location.protocol
: Contains the protocol of the URL as aDOMString
, followed by a:
.location.host
: Contains the domain name as aDOMString
, possibly followed by a:
and the URL's port number.location.hostname
: Contains the domain name of the URL as aDOMString
.location.port
: Contains the port number as aDOMString
.location.pathname
: Contains the path component of the URL as aDOMString
, starting with a/
.location.search
: Contains the URL parameters as aDOMString
, starting with a?
.location.hash
: Contains the fragment identifier as aDOMString
, starting with a#
.location.origin
: Read-only, contains the standard formDOMString
of the page's domain of origin.location.ancestorOrigins
: Read-only, returns a staticDOMStringList
that includes in reverse order the origins of all ancestor browsing contexts associated with the givenLocation
object. This can be used to determine if a site has framed aniframe
document. This property is currently still in the proposal stage.
location.assign()
: Loads the content resource of the given URL to the object associated with thisLocation
object, effectively loading a new document.location.reload()
: Reloads the resource from the current URL, with a special optional parameter of typeBoolean
. When this parameter istrue
, the method will always force the refresh to load data from the server. If the parameter isfalse
or not specified, the browser may load the page from cache.location.replace()
: Replaces the current resource with the given URL. Unlike theassign()
method, the new page replaced byreplace()
will not be stored in the session history, meaning the user cannot return to the page using the back button.location.toString()
: Returns aDOMString
containing the entire URL, equivalent to readinglocation.href
, but using it will not modify the value oflocation
.
https://github.com/WindrunnerMax/EveryDay
https://developer.mozilla.org/zh-CN/docs/Web/API/Location