简体   繁体   English

如何导航到页面,但要确保目标页面将被刷新

[英]how can I navigate to page but ensure that the target page will be refreshed

I have a Login.html page from which I'm navigating to my Main.html 我有一个Login.html页面,从该页面导航到Main.html

now when I;m doing a logout I want to navigate back to the login.html but I also want to ensure this page will be refreshed. 现在,当我要注销时,我想导航回到login.html,但我也想确保此页面将被刷新。 I don't want to disable the page cache, I just want only in this specific scenario to navigate it after refresh. 我不想禁用页面缓存,我只希望在这种特定情况下刷新后对其进行导航。

I tried the following: 我尝试了以下方法:
window.location.replace but it doesn't refresh the page. window.location.replace但不会刷新页面。
window.location.href - also doesn't refresh the page. window.location.href也不会刷新页面。
window.location.reload() - Refresh only the current page. window.location.reload() -仅刷新当前页面。

@Christof13 suggestion regarding passing a parameter is the only way I can see but it loading the page twice and it's very ugly, @ Christof13关于传递参数的建议是我唯一看到的方法,但是它两次加载页面,非常丑陋,

any other suggestions? 还有其他建议吗?

How about setting a Timeout on the logout event? 如何设置注销事件的超时时间? This way, the location reloads only once. 这样,该位置仅重新加载一次。

$("#myLogOutButtonOrLink").click(function() {
    setTimeout(function(){
        window.location.reload();
        }, 1000);
});

My solution was using a global variable on the window scope as the following: 我的解决方案是在窗口范围内使用全局变量,如下所示:

on main.html: 在main.html上:

window.globals.RefreshRequired = true

on Login.html: 在Login.html上:

if (window.globals && window.globals.RefreshRequired) {
            window.location.reload();
        }

In this way the refresh will be done if I already visited main.html during the current browser instance. 这样,如果我在当前浏览器实例期间已经访问过main.html,刷新将完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM