Js gets the url of the current page

  • 2020-03-30 03:18:08
  • OfStack

1. Set or get the whole URL as a string:

Window. The location. The href

2. Set or get the port number associated with the URL:

Window. The location. The port

3. Set or get the protocol part of the URL

Window. The location. The protocol

4. Sets or gets the part of the href attribute that follows the question mark

Window. The location. The search

5. Get the value of the variable (intercept the part after the equal sign)
 
var url = window.location.search; 
// alert(url.length); 
// alert(url.lastIndexOf('=')); 
var loc = url.substring(url.lastIndexOf('=')+1, url.length); 

6. Set or get the protocol part of the URL:

Window. The location. The protocol

7. Set or get the section in the href attribute after the well number "#" :

Window. The location. The hash

8. Set or get the hostname and port number of the location or URL:

Window. The location. The host

Related articles: