Friday, April 27, 2012

Disable Back Button in asp.net using Javascript


<script type="text/javascript">
     var storedHash = window.location.href;
     function changeHashOnLoad() {
         window.location.href += "#";
         setTimeout("changeHashAgain()", "50");
     }

     function changeHashAgain() {
         window.location.href += "1";
     }


     window.setInterval(function () {
         if (window.location.href != storedHash + "#") {
             window.location.href = storedHash + "#";
         }
     }, 50);

     function noBack() { window.history.forward(1); }
    </script>


<body style="background: White;"  onload="changeHashOnLoad();" onunload="" onpageshow="if (event.persisted) noBack();">
</body>

No comments:

Using Authorization with Swagger in ASP.NET Core

 Create Solution like below LoginModel.cs using System.ComponentModel.DataAnnotations; namespace UsingAuthorizationWithSwagger.Models {     ...