Js method used to obtain information about the current page url (JS get the current URL information)

1, Sets or specify the file name or path.

alert(window.location.pathname)

2, set or get the entire URL string.

alert(window.location.href);

3, port number set or get associated with the URL.

alert(window.location.port)

4, set or get protocol part of the URL.

alert(window.location.protocol)

5, set or get the segment in the href attribute "#" followed by the pound sign.

alert(window.location.hash)

6, set or get the hostname and port number location or URL.

alert(window.location.host)

7, set or get the href attribute section follows the question mark.

alert(window.location.search)

8, acquisition variable value (taken back portion equal)

 var url = window.location.search;

//    alert(url.length);

//    alert(url.lastIndexOf('='));

var loc = url.substring(url.lastIndexOf('=')+1, url.length);

9, used to get the domain name of the current page

var domain = document.domain;

Transfer: https://www.cnblogs.com/chongyao/p/6898192.html

Guess you like

Origin blog.csdn.net/cillent_boy/article/details/90918349