如何在导航中使用eventlistener,除了两件事

How to use eventlistener on navigation EXCEPT on 2 things

本文关键字:两件 导航 eventlistener      更新时间:2023-09-26

我有两个剑道菜单,我希望在其中重新加载页面。然而,根据我们客户的请求,他们不希望用户能够单击后退按钮。这是我使用的代码:

<script>
history.pushState(null, null, 'HomePage');
    window.addEventListener('popstate', function(e) {
            history.pushState(null, null, 'HomePage');
    });
</script>

基本上,我想在所有事情上触发该事件,除了点击这两个剑道菜单上的一个菜单项。

感谢

我把这段代码放在_layout.cshtml中MVC项目的部分中,以最终解决问题。我仍然遇到的唯一问题是右键单击返回按钮的功能仍然存在。

代码:

    history.pushState(null, null, $(location).attr('href'));
    window.addEventListener('popstate', function () {
        history.pushState(null, null, $(location).attr('href'));
    });