Click here to Skip to main content
14,931,965 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Experts,


this is for online examination..

How to disable browser back and refresh button while writing the exam..


or

How to show warning message when user try to refresh or press back button using javascript
Posted
Comments
Boipelo 11-Sep-13 6:48am
   
The question has been answered a hundredth time. Use the search at top right for an answer.

Put this code..
code contain every possible solutions.

VB
<System.Web.Services.WebMethod()> _
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Request.UrlReferrer Is Nothing OrElse String.IsNullOrEmpty(Request.UrlReferrer.AbsolutePath) Then
Session.Abandon()
Response.Redirect("../Default.aspx")
' Server.Transfer("../Default.aspx", False)
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.Expires = -1500
Response.CacheControl = "no-cache"
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1))
Response.Cache.SetNoStore()

Response.AppendHeader("Refresh", Convert.ToString((Session.Timeout * 1) + 1) + "; URL=Default.aspx")
FormsAuthentication.SignOut()

Session.Abandon()
End If
   
Why? There should be some better way to handle this. As you can do this,but its not a good idea. One thing is, you can open the required page in new window where there is no toolbar. e.g.
C#
<script type="text/javascript">
  function opennew(url) {
      var win= window.open(url, '','scrollbars=no,menubar=no,resizable=yes,toolbar=no,location=no,status=no');
      }  
  </script>

with Onclick function you can call this function like:
C#
onclick="opennew('http://www.google.com');"

Regards..:)
   
v4
Comments
Harsha24 11-Sep-13 7:16am
   
yup even that is ok for me..like opening a page where there is no toolbar
Thanks7872 11-Sep-13 7:31am
   
Refer to updated answer. This is the way how it should be handled.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900