How to disable F5 keyword using Javascript in asp.net ?


We can disable F5 Keyword using Javascript like this

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CloseBrowserTest.aspx.cs" Inherits="CloseBrowserTest" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">;
<head id="Head1" runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
document.attachEvent("onkeydown", my_onkeydown_handler)
function my_onkeydown_handler()
{
if(event.keyCode == 116)
{
event.keyCode = 0;
event.returnValue = false;
}
}
</script>

</head>
<body onload="return my_onkeydown_handler()">
<form id="form1" runat="server">
<div>

</div>
</form>
</body>
</html>

Advertisement

3 thoughts on “How to disable F5 keyword using Javascript in asp.net ?

  1. simran October 7, 2013 / 10:25 am

    nice code

  2. rosauragrasser September 8, 2014 / 10:00 pm

    I like the helpful info you provide in your articles.
    I’ll bookmark your weblog and check again here regularly.
    I’m quite certain I will learn lots of new stuff right here!
    Best of luck for the next!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.