The content of this article is the processing of URLs by JS. Now I will share it with you. Friends who are interested can also refer to the content of this film
///Call
/// var request = GetRequestParms();
/// request["parameter"]
function GetRequestParms(name) {
var url = location.search ; //Get the string after the "?" character in the url
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&");
for (var i = 0; i < strs.length; i++) {
if (strs[i] .split("=")[0].toLowerCase() == name) {
continue; (strs[i].split("=")[1]);
} }
}
return theRequest;
}
///Append or change Url parameters
/ //Example changeURLPar(test, 'id', 99); // http://www.huistd.com/?id=99&ttt=3
///changeURLPar(test, 'haha', 33); / / http://www.huistd.com/?id=99&ttt=3&haha=33
function changeURLPar(destiny, par, par_value) {
var pattern = par + '=([ ^&]*)';
var replaceText = par + '=' + par_value;
if (destiny.match(pattern)) {
var tmp = '/\\' + par + '= [^&]*/';
tmp = destiny.replace(eval(tmp), replaceText);
return (tmp);
}
else {
if (destiny.match ('[\?]')) {
RETURN DESTINY + '&' + Replacetext;
}
Else {
Return Destiny + '?' + Replacetext;
} }
return destiny + '\n' + par + '\n' + par_value;
}
///Example changeURLParm(test, 'id', 99); / / http://www.huistd.com/?id=99&ttt=3
///changeURLParm(test, 'haha', 33); // http://www.huistd.com/?id=99&ttt =3&haha=33
function changeURLParm(url, ref, value) {
var str = "";
if (url.indexOf('?') != -1)
str = url .substr(url.indexOf('?') + 1);
else
return url + "?" + ref + "=" + value;
var returnurl = "";
var setparam = "";
var arr;
var modify = "0";
if (str.indexOf('&') != -1) {
arr = str.split(' & ');
for (I in ARR) {
if (ARR [i] .split (' = ') [0] == Ref) {
setparam = value;
Modify = “1”; ('=')[0] + "=" + setparam + "&";
returnurl 0 ")
If (Returnurl == Str)
Returnurl = Returnurl +" & " + Ref +" = " + Value;
Else {
if (str.InDexof ( '=') != -1) {
arr = str.split('='); " 1"; if (modify = = "0")
if (returnurl == str)
’ s ’ s ’ s ’ s ’ s ‐ ‐ ‐ ‐ ‐ ‐ returnurl = returnurl + "&" + ref + "= " + value; }
return url.substr(0, url.indexOf('?')) + "?" + returnurl;
}
Related recommendations:
How to use URL to obtain web page content in php
The above is the detailed content of JS handles URLs. For more information, please follow other related articles on the PHP Chinese website!