获取带#号的url hash
taxpayerid: any = 'id';
//获取url 中id后的参数
getUrlParam(name) {
const reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)') // 构造一个含有目标参数的正则表达式对象
const r = window.location.hash.split("?")[1].match(reg) // 匹配目标参数
console.log(r);
if (r != null) {
return unescape(r[2]) // 返回参数值
} else {
return null
}
}
ngOnInit() {
let g = this.getUrlParam(this.taxpayerid);//获指定参数
}
获取没有#号的url
//获取url中的参数方法
getUrlParam(name) {
//构造一个含有目标参数的正则表达式对象
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
// var reg = new RegExp("(^|&)" + name);
//匹配目标参数
var r = window.location.search.substr(1).match(reg);
//返回参数
if (r != null) {
console.log(r);
console.log(r[2]);
return r[2]
} else {
return null;
}
}