In JS window.location.search The usage and function of.

Time:2020-8-1

Use this property to get the page URL address:

window.location The properties contained in the object

 

attribute describe
hash URL (anchor) starting from hash (ා)
host The port number of the host name and current URL
hostname The host name of the current URL
href Full URL
pathname The path part of the current URL
port Port number of the current URL
protocol Protocol for the current URL
search URL from question mark (?) (query section)


 

As shown in the figure, the parameters in the URL are taken out.

JS script capture the parameters of the page get method request? In fact, it can be used directly window.location.search Then, split method combined with loop traversal of free-form data format is used.

The general treatment is as follows:

 

 var searchURL = window.location.search;
 searchURL = searchURL.substring(1, searchURL.length);
 var targetPageId = searchURL.split("&")[0].split("=")[1];