当前位置:网站首页>Location object

Location object

2020-12-06 11:01:16 WindrunnerMax

Location object

Location Object represents the location of the object to which it is linked URL, The changes are reflected in the objects associated with them .Document and Window Objects have such a link to Location, Pass respectively document.location and window.location visit .

attribute

  • location.href: Including the whole URL One of the DOMString,DOMString It's a UTF-16 character string , because JavaScript This string has been used , therefore DOMString Map directly to a String.
  • location.protocol: contain URL One of the corresponding protocols DOMString, Finally, there is one :.
  • location.host: Contains a domain name DOMString, There may be a... At the end of the string : And keep up URL Port number .
  • location.hostname: contain URL One of the domain names DOMString.
  • location.port: One that contains the port number DOMString.
  • location.pathname: contain URL One of the middle paths DOMString, There's a beginning /.
  • location.search: contain URL One of the parameters DOMString, There's a beginning ?.
  • location.hash: Containing the block identifier DOMString, There's a beginning #.
  • location.origin: read-only , The standard form of the domain name that contains the source of the page DOMString.
  • location.ancestorOrigins: read-only , The return structure is static DOMStringList, Include and give in reverse order Location The source of all ancestors of the document associated with the object , According to location.ancestorOrigins To determine the architecture of a site iframe file , This attribute is still in the proposal .

Method

  • location.assign(): Load given URL Content resources to this Location On the object to which the object is associated , To load a new document .
  • location.reload(): Reload from current URL Resources for , It has a special optional parameter , The type is Boolean, The parameter is true The refresh caused by this method will definitely load data from the server , If it is false Or this parameter is not specified , Browsers may load pages from the cache .
  • location.replace(): Use the given URL Replace the current resource , And assign() The different way is to use replace() The replaced new page will not be saved in the session history History in , This means that users will not be able to use the back button to go to the page .
  • location.toString(): Return to one DOMString, Including the whole URL, It and read location.href The effect is the same , But it can't be modified with it location The value of the .

A daily topic

https://github.com/WindrunnerMax/EveryDay

Reference resources

https://developer.mozilla.org/zh-CN/docs/Web/API/Location

版权声明
本文为[WindrunnerMax]所创,转载请带上原文链接,感谢
https://chowdera.com/2020/12/202012061101103121.html