如果是hash路由,有hash值,#
window.location.search 的值为空 可以使用下面的方法
如果是iframe的父网页,那么要用window.top
iframe可以直接获取,和打开一个新网页一样
const getAllParams = () => {
// 获取地址中的地址
let href = window.location.href;
// 截取问号后面的query参数
let query = href.substring(href.indexOf("?") + 1);
// 以&符号分割
let item = query.split("&");
let obj = {};
for (let i = 0; i < item.length; i++) {
let arr = item[i].split("=");
// 参数名,参数值 赋值 对象的属性名,属性值
obj[arr[0]] = arr[1];
}
return obj;
};
let querys = getAllParams();
console.log(querys.ticket);