繁体   English   中英

当用户再次导航时,强制刷新/重新加载

[英]Force refresh/reload when user navigates Back and forward again

我想知道当用户按下后退按钮然后再次按下前进时如何确保页面重新加载/刷新。 请帮忙!

您可以使用cookie来设置“按下后退按钮”标志。

例如。 jQuery + jQuery Cookie插件

    $(document).ready(function($) {
      if ($.cookie("reload") === *YOUR-PAGE-ID*) {

        $.removeCookie("reload");
        location.reload();

      } else if (window.history && window.history.pushState) {

        window.history.pushState("forward", null, "./#forward");

        $(window).on("popstate", function() {
          $.cookie("reload", *YOUR-PAGE-ID*); // set cookie with some page id
        });

      }
    });

由于旧版浏览器不支持popstate因此您应该使用history.js

<input type='button' onclick="window.location=window.location.href;">

演示在我的网站http://vitideas.in/stackoverflow/

暂无
暂无

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

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