Summed up a number of methods to compress it into a function object, only dozens of lines of code, the use of the method is simple and straightforward
Save As Ojburl.js
Copy Code code as follows:
/*
Description: This code can be freely copied and used, but please keep the author information!
Author:kevin website:http://iulog.com/qq:251378427
JS operation URL function use instructions:
Initialization of Var myurl=new objurl (); You can also customize Url:var myurl=new objurl (' http://www.jb51.net ');
Read URL parameter value var val=myurl.get (' abc '); Reading the value of the parameter ABC
Sets the URL parameter myurl.set ("ARG", data); Add/Modify the value of an arg parameter is data
Removes the URL parameter myurl.remove ("Arg"); Remove arg parameter
Gets the processed URL myurl.url ();//generally executes the jump Location.href=myurl.url () directly;
Debugging interface: Myurl.debug (); Modify the function for debugging
*/
function Objurl (URL) {
var ourl=url| | Window.location.href;
var href= ""; the front section
var Params={};//url Parameter Object
var jing= "";//#及后面部分
var init=function () {
var Str=ourl;
var index=str.indexof ("#");
if (index>0) {
JING=STR.SUBSTR (index);
Str=str.substring (0,index);
}
Index=str.indexof ("?");
if (index>0) {
Href=str.substring (0,index);
Str=str.substr (index+1);
var parts=str.split ("&");
for (Var i=0;i<parts.length;i++) {
var kv=parts[i].split ("=");
PARAMS[KV[0]]=KV[1];
}
}else{
Href=ourl;
params={};
}
};
This.set=function (key,val) {
Params[key]=encodeuricomponent (Val);
};
This.remove=function (key) {
if (key in params) params[key]=undefined;
};
This.get=function (key) {
return Params[key];
};
This.url=function (key) {
var strurl=href;
var objps=[];
For (var k in params) {
if (Params[k]) {
Objps.push (+ + "=" +params[k]);
}
}
if (objps.length>0) {
strurl+= "?" +objps.join ("&");
}
if (jing.length>0) {
strurl+=jing;
}
return strurl;
};
This.debug=function () {
The following debug code freedom settings
var objps=[];
For (var k in params) {
Objps.push (+ + "=" +params[k]);
}
alert (OBJPS);//output params all values
};
Init ();
}
Call method
JS operation URL function use instructions:
[Code]
var myurl=new objurl (); Class You can also customize Url:var myurl=new objurl (' http://www.jb51.net ');
var val=myurl.get (' abc '); Reading the value of the parameter ABC
Myurl.set ("Arg", data); Add/Modify the value of an arg parameter is data
Myurl.remove ("Arg"); Remove arg parameter
Myurl.url ();//Get the URL after processing, generally direct execution of the Jump: Location.href=myurl.url ();
Myurl.debug (); This is the debugging interface. Modify the function method to debug