To run the results first
Here is the page code
Testjsgeturlattribute.html
<script>varRout = Geturlattribute (' rout ');if(NULL!=rout) {alert (rout);}/** * 20150514 14:30 * Ro * gets its value based on the key name in the URL query string */ function geturlattribute(paramename) { //location.search is a string that starts with the current URL's?, which is the query string varquery = (Location.search.length >0? Location.search.substring (1) :NULL);if(NULL!=query) {varargs =New Object( );varPairs = Query.split ("&"); for(vari =0; i < pairs.length; i++) {varpos = Pairs[i].indexof ("=");if(pos = =-1)Continue;varArgname = pairs[i].substring (0, POS);varValue = pairs[i].substring (pos+1); Value =decodeuricomponent(value); Args[argname] = value; }//Get value based on key name returnArgs[paramename]; }return NULL;}</script>
The principle is to use the location object in JavaScript, which provides information about the document loaded in the current window, and provides some navigational features.
The Location object is a very special object because it is both a property of the Window object and a property of the Document object.
Window.location and Document.location refer to the same object.
The purpose of a Location object is not only to preserve the information of the current document, but also to parse the URL into separate fragments, which can be accessed through different properties.
The following table is all the properties of the Location object:
Although you can use the above properties to access most of the information for a location object, it is not convenient to access the properties in the query string that the URL contains.
Although Location.search returns everything from the question mark to the end of the URL, there is no way to access each of these query string parameters individually.
So, I created the function above to parse the query string and return its value based on the key name.
JS gets its value based on the key name in the URL query string