Two Methods for javascript to obtain the current URL parameter:
// Return a string parameter, for example, class_id = 3 & id = 2 & function getUrlArgStr () {var q = location. search. substr (1); var qs = q. split ('&'); var argStr = ''; if (qs) {for (var I = 0; I <qs. length; I ++) {argStr + = qs [I]. substring (0, qs [I]. indexOf ('=') + '=' + qs [I]. substring (qs [I]. indexOf ('=') + 1) + '&';} return argStr ;}
// The returned Parameter function getUrlArgObject () {var args = new Object (); var query = location. search. substring (1); // obtain the query string var pairs = query. split (","); // disconnect for (var I = 0; I <pairs. length; I ++) {var pos = pairs [I]. indexOf ('='); // find name = valueif (pos =-1) {// if not found, skip continue;} var argname = pairs [I]. substring (0, pos); // extract namevar value = pairs [I]. substring (pos + 1); // extract valueargs [argname] = unescape (value); // save as attribute} return args; // return object}
In addition, it lists some functional methods for javascript to obtain each part of the url:
Window. location. host; // return the host part of the url, for example, www.xxx.com.
Window. location. hostname; // return www.xxx.com
Window. location. href; // return the entire url string (the complete address bar in the browser), for example: www.xxx.com/index.php? Class_id = 3 & id = 2
Window. location. pathname; // return/a/index. php or/index. php
Window. location. protocol; // return the url protocol, such as http:, ftp:, maito:, and so on.
Window. location. port // The port part of the url. If the default port 80 is used, the return value is not the default port 80, but an empty character.
Articles you may be interested in
- PHP retrieves the complete url function of the current page, including Parameters
- Windows cannot start the hardware device because its configuration information (in the Registry) is incomplete or damaged. (Code 19) Solution
- Js modifies the value of a specified parameter in the url
- JavaScript calculates the number of characters currently entered
- Jquery obtains the index number of the current element in the Peer element.
- Mysql queue for efficient Concurrent Data Reading
- Js checks whether the image is loaded and obtains the image width.
- JavaScript to get the number of rows and columns of a table