简体   繁体   English

禁用弹出窗口中的后退按钮

[英]To disable back button in popup window

In the below code I have JavaScript function for disable function in pop window in master page but it is not disabling the back button. 在下面的代码中,我具有JavaScript功能,可在母版页的弹出窗口中禁用功能,但未禁用后退按钮。 Please help me to solve the issue. 请帮我解决问题。 Pop.master 流行音乐大师

window.onload = function () {
    noBack();
}
function noBack() {
    this.history.forward();
}

My opinion is that ; 我的看法是; you shouldn't do it because of causing bad user engagement. 您不应该这样做,因为会引起用户的不良参与。 It also makes your page untrustable. 这也使您的页面不可信任。

But for chrome and firefox this should be work; 但是对于chrome和firefox,这应该有效;

Put This script on head of your page and change 'pagename' to your page name. 将此脚本放在页面的顶部,然后将“ pagename”更改为页面名称。

<script type = "text/javascript" >
    history.pushState(null, null, 'pagename');
    window.addEventListener('popstate', function(event) {
    history.pushState(null, null, 'pagename');
});
</script>

Note: This script must be on head of your page. 注意:此脚本必须位于页面的顶部。

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

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