Search - Articles - Dev Forums - Favorites - Member Login
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009


Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Build the right apps the right way with powerful development tools.
Visual Studio 2010. Learn more...
Block Navigation and Other Option on Web Page Using JavaScript

Author: DevASP
Download Source Code : 470_LockNavigations.zip

This article is about how you can disable the back, forward, refresh options over a web page. Download the project and run it in a new IE. When the page is browsed press F5, Backspace or Alt Backspace.

  • Steps you will do. 
  • Start visual studio and create a new web application. 
  • Open the HTML design of your web page and before closing the head tag add the following JavaScript functions to block the options.

 

<SCRIPT LANGUAGE="JAVASCRIPT">

var oLastBtn=0;

            bIsMenu = false;

           

            if (window.Event)

            document.captureEvents(Event.MOUSEUP);

            function nocontextmenu()

            {

            event.cancelBubble = true

            event.returnValue = false;

            return false;

            }

            function norightclick(e)

            {

            if (window.Event)

            {

            if (e.which !=1)

            return false;

            }

            else

            if (event.button !=1)

            {

            event.cancelBubble = true

            event.returnValue = false;

            return false;

            }

            }

            document.oncontextmenu = nocontextmenu;

            document.onmousedown = norightclick;

 

 

             function onKeyDown() {

                        if ( (event.altKey) || ((event.keyCode == 8) &&

                           (event.srcElement.type != "text" &&

                            event.srcElement.type != "textarea" &&

                            event.srcElement.type != "password")) ||

                           ((event.ctrlKey) && ((event.keyCode == 78) ||

                            (event.keyCode == 82)) ) ||

                            (event.keyCode == 116) ) {

 

                               event.keyCode = 0;

                               event.returnValue = false;

                        }

             }

</SCRIPT>

 

 

Now add the following HTML code to design the page and call the JavaScript functions written above.

 

<BODY onKeyDown="onKeyDown();" BGCOLOR="#009999">

    <form id="Form1">

     <center>

       <H4> NO REFRESH, NO BACKSPACE, NO ALT-BACKSPACE</H4>

                  Always Open it in new IE

       <H4>Dont forget to visit www.devasp.net </H4>

       <a href="http://www.devasp.com" > Devasp Team </a>

     </center>

    </form>

</BODY>

Run your application in a new browser and check for the option, they are disabled.

Article Comments
It is good for javascript but I need for asp.net with VB. please send it to me by address about

Posted on 12/20/2006 8:16:25 PM by jhon

helo...i would like to know how we can enable downloading and uploading actions in a website.....pls send it its very urgent...

Posted on 3/3/2007 4:01:36 AM by vivek

Block Navigation and Other Option on Web Page Using JavaScript

Posted on 6/29/2007 4:33:16 AM by susanta

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Display Flash Text On a Web Page Using JavaScript

Disclaimer - Privacy
© 2002-2010 DevASP.net