There is a URL such as the following:
Http://passport.csdn.net/account/login?
From=http%3a%2f%2fwrite.blog.csdn.net%2fpostedit
How do we get the value from this parameter? Search the online method is very easy, such as the following, the first is through the regular. Another way to put the array into a string by slicing it:
Method One:
function getquerystring (name) {var reg = new RegExp ("(^|&)" + name + "= ([^&]*) (&|$)", "I"); var r = Window.loca TION.SEARCH.SUBSTR (1). Match (reg); if (r = null) return unescape (r[2]); return null;} var from = getquerystring (' from '); alert (from);
Method Two:
function Getrequest () {var url = location.search;//Get URL in "?" Character string var therequest = new Object (); if (Url.indexof ("?")! =-1) {var str = URL.SUBSTR (1); STRs = Str.split ("&"); for (var i = 0; i < strs.length; i + +) {therequest[strs[i].split ("=") [0]]=unescape (Strs[i].split ("=") [1]);}} return therequest; } var req = Getrequest (); var from = req["from"];alert (from);
JS gets the URL to the number of two ways to explain the specific