Get the page jump parameters js
Window.location.href page by page or jump through window.parent.location.href, how to obtain the corresponding parameters in the new page it?
window.location.href way
Which remove the "#" sign is because the url parameter also added a # parameter.
function GetRequest(name) {
var url = window.location.search; //获取url中"?"符后的字串
// var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
if(str.indexOf("#" != -1)){
str = str.substr(0);
}
strs = str.split("&");
for(var i = 0; i < strs.length; i ++) {
if(strs[i].indexOf(name) != -1){
return strs[i].split("=")[1];
}
}
}
return null;
}
window.parent.location.href
function GetRequest(name) {
var url = window.parent.location.search; //获取url中"?"符后的字串
// var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
if(str.indexOf("#" != -1)){
str = str.substr(0);
}
strs = str.split("&");
for(var i = 0; i < strs.length; i ++) {
if(strs[i].indexOf(name) != -1){
return strs[i].split("=")[1];
}
}
}
return null;
}
This difference between the two places is to get the url, keeping up with the way the page jump.
other methods
The network also provides other ways, can be obtained above with reference to the corresponding modified url manner.
function GetRequest() {
var url = window.location.search; //获取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 ++) {
theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
}
}
return theRequest;