iframe或frameset中,子页面获取父页面的地址。
function getParentUrl() {
var url = null;
//判断是否是iframe或其他嵌套方式
if (window.parent !== window.self) {
try {
let {protocol,host,port} = window.top.location;
url= protocol + '//' + host + (port?':'+port:'');
}catch (e) {
let filterArr = document.referrer.split('/');
url = filterArr[0] + '//' + filterArr[2];
}
}
return url;
}