iframe 內 Session 過期跳轉登入頁,導致父頁面也被跳轉或刷新,體驗差。
**登入頁不應在 iframe 內載入**,應導向**頂層視窗**或**新視窗**完成登入,再通知 iframe 刷新。
登入頁/Session 攔截器回傳:
<script>top.location.href = '/login?redirect=' + encodeURIComponent(top.location.href);</script>
父頁面直接跳轉登入,登入成功後 `top.location.href = redirectUrl` 返回原頁。
window.addEventListener('message', e => {
if (e.data.type === 'session_expired') {
// 彈出登入模態框或新視窗
window.open('/login?iframe=1', 'loginWin', 'width=400,height=500');
}
});
opener.postMessage({type:'login_success', token:'...'}, '*');
window.close();
定期請求 `/keepalive` 延長 Session,避免過期。