Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the use of location in javascript

Shulou Source: shulou.com Published: 2022-06-03 16:52:05 11月14日 Update

Editor to share with you what is the use of location in javascript, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

The location address object describes the address opened by a window object. To represent the address of the current window, simply use "location"; to represent the address of a window, use ".location".

Protocol returns the protocol of the address, with a value of 'http:','https:','file:', etc.

Hostname returns the hostname of the address, for example, an "http://www.microsoft.com/china/" address, location.hostname = = 'www.microsoft.com'."

Port returns the port number of the address. Generally, the port number of http is' 80'.

Host returns the host name and port number, such as: 'www.a.com:8080'.

Pathname returns the pathname, such as "http://www.a.com/b/c.html" journal location.pathname = = 'bmax e.html'.

Hash returns "#" and later content, such as "http://www.a.com/b/c.html#chapter4" location. Hash ='# chapter4';. If there is no" # "in the address, an empty string is returned.

Search returns "?" And later content, such as "http://www.a.com/b/c.asp?selection=3&jumpto=4" selection=3&jumpto=4';. Search ='? if there is no"? "in the address, an empty string is returned.

Href returns all of the above, that is, the entire address. Return it as it is displayed in the browser's address bar. If you want a window object to open an address, you can use "location.href = '...'" or you can directly use "location = '...'" To achieve this goal.

Method

Reload () is equivalent to pressing the "IE" or "Reload" (Netscape) keys on the browser.

Replace () opens a URL and replaces the address of the current location in the history object. After opening a URL in this way, pressing the browser's "back" button will not return to the previous page.

The above is all the content of this article "what is the use of location in javascript?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Address content object slogan browser article browse host method empty character not much that is location history most more purpose knowledge industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Technology OPPO Reno MySQL Shulou Tech Info