用到了浏览器的location对象获取url相关信息,代码如下:
//获取url参数
function geturlParam() {
var url = location.search; //获取url中含"?"符后的字串
var urlParam = {};
if (url.indexOf("?") !== -1) {
var str = url.substr(1);
var strs = str.split("&");
for (var i =0; i < strs.length; i++) {
urlParam[strs[i].split("=")[0]] =decodeURI(strs[i].split("=")[1]);
}
}
return urlParam;
}
var urlParam =geturlParam();
if (urlParam.name) {//获取url中name参数
console.log("参数中获取到的频点数据范围是:" + urlParam.name);
//todo
}
附 更多关于location对象:
location.href //一个完整url
location.protocol;//'http'
location.host;//'www.example.com'
location.port;//'8080'
location.pathname;//'/path/index.html'
location.search;//'?a=1&b=2'
location.assign("http:www.baidu.com")//加载新页面,请在F12工具中尝试
location.reload()//重新加载当前页面,请在F12工具中尝试
参考 浏览器对象(廖雪峰)