Home > Web Front-end > JS Tutorial > body text

JS handles URLs

不言
Release: 2018-04-04 13:26:13
Original
1765 people have browsed it

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:

JS Detailed explanation of form value transfer and URL encoding conversion

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!