简体   繁体   English

如何清除Windows``推''状态

[英]How to clear windows `push` state

I am using history.push() state to prevent the web page by the user for client requirements. 我正在使用history.push()状态来阻止用户浏览网页以满足客户需求。

for that, I use the following code : 为此,我使用以下代码:

history.pushState(null, null, document.URL);
    $(window).on('popstate', function () {
        history.pushState(null, null, document.URL);
});

works fine. 工作正常。 But in the next page, I am not able to use the back button, since the above code sets in global space. 但是在下一页中,由于上述代码在全局空间中设置,因此我无法使用后退按钮。 so how to clear the history push state any make browser again in the normal? 那么如何清除历史推送状态使浏览器又恢复正常呢?

Thanks in advance. 提前致谢。

Ideally pushState is used to push a new URL to the address bar. 理想情况下, pushState用于将新URL推送到地址栏。

You need to add a listener to the popstate event. 您需要向popstate事件添加一个侦听器。

This will be when you click the back button after pushing a state, the page receives the event. 这将是您在按下状态后单击“后退”按钮时,页面收到事件。

In it you need to replace the page contents with the correct page. 在其中,您需要用正确的页面替换页面内容。

window.onpopstate = function(event) {    
    if ( event && event.state ) {
        location.reload(); 
    }
}

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

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