简体   繁体   English

如何在应用程序重新打开时强制移动浏览器重新加载页面

[英]How to force mobile browsers to reload the page when the application is reopened

As you may know, in chrome or firefox mobile, when you are visiting a webpage, if you close the browser and then open again, the first thing the app does is to open that webpage again, but it opens the version you left when you closed, so, for example if you're watching a forum thread with 4 posts and close, the next time you open you see the same thread with the same 4 posts even if there were new posts, the only way you can know is reloading the page.您可能知道,在 chrome 或 firefox mobile 中,当您访问网页时,如果您关闭浏览器然后再次打开,应用程序所做的第一件事就是再次打开该网页,但它会打开您离开时离开的版本已关闭,因此,例如,如果您正在观看包含 4 个帖子的论坛主题并关闭,则下次打开时您会看到同一主题包含相同的 4 个帖子,即使有新帖子,您唯一能知道的方法就是重新加载这一页。

I'm facing issues because my session variables expires but the page in a previous version is opened and then I get loads of notices due to the session variables not being defined.我遇到了一些问题,因为我的会话变量已过期,但打开了以前版本中的页面,然后由于未定义会话变量而收到大量通知。

I need to find a way to force the mobile browser to open a fresh instance of my page, so if the session variables already expired, the user is redirected to the proper page.我需要找到一种方法来强制移动浏览器打开我页面的新实例,因此如果会话变量已经过期,用户将被重定向到正确的页面。

Thanks in advance.提前致谢。

If you use a library like axios , you can handle errors caused by your invalid session with interceptors and trigger a page reload programmatically.如果您使用像axios这样的库,您可以处理由拦截器的无效会话引起的错误,并以编程方式触发页面重新加载。

axios.interceptors.response.use(function (response) {
  return response;
}, function(error) (
  if(error.statusCode === 401)
    window.location.reload(); //or whatever
  return error;
});

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

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