简体   繁体   中英

How to prevent user from going back to previous page in ASP.NET

I have tried this, but the back page is showing for 1 or 2 secs and after that it comes back to the current page. I don't want to go to Backpage even for 1 or 2 sec.

<script type="text/javascript">
    function preventBack() { window.history.forward(); }
    setTimeout("preventBack()", 0);
    window.onunload = function () { null };
</script>

I have write this code in Asp.net.aspx file.

Is their any other way?

What you are wanting to do is client side logic. So asp.net vs node vs php doesn't really enter into this.

You are on the correct track. I'd suggest adding a window.history.pushState({}, '', window.location) to your initial code so the browser sees the first back button press as hitting the same page. Also check out window.onhashchange

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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