如何判断当前页面是从 iframe 访问的,还是直接访问的?
参考
https://yq.aliyun.com/articles/2977?spm=0.0.0.0.3mTODl
/判断当前页面是否直接显示在浏览器中
if (self == top) {
//跳转
window.location.replace("/blog/timeline/");
// window.location.href='/blog/timeline/';
}
如果self==top,则证明不是来自iframe
其中 window.location.replace 跳转时,浏览器历史不记录跳转之前的那一条 URL,而 window.location.href 会把跳转前后的 URL 都记录在浏览器中。
如果想要模拟点击链接的跳转效果,使用 window.location.href,如果想要模拟 HTTP 跳转,使用 window.location.replace。
参考
https://yq.aliyun.com/articles/2977?spm=0.0.0.0.3mTODl
/判断当前页面是否直接显示在浏览器中
if (self == top) {
//跳转
window.location.replace("/blog/timeline/");
// window.location.href='/blog/timeline/';
}
如果self==top,则证明不是来自iframe
其中 window.location.replace 跳转时,浏览器历史不记录跳转之前的那一条 URL,而 window.location.href 会把跳转前后的 URL 都记录在浏览器中。
如果想要模拟点击链接的跳转效果,使用 window.location.href,如果想要模拟 HTTP 跳转,使用 window.location.replace。