Summary


Suppressing a Context Menu for Web Pages

Suppressing the context menu for a Web page does take some work. You will have to capture every mouse event for the entire page, differentiate between context menu mouse clicks and normal mouse clicks, and then ask the browser not to show the context menu. The whole process might look something like this:

 <script language=JavaScript>  <!--      function clickIE4()      {         if ( event.button==2 )         {             return( false );          }      }      function clickNS4(e)       {         if( document.layers || document.getElementById && !document.all )         {        if( e.which == 2 || e.which == 3 )         {           return( false );        }      }    }    if( document.layers )     {       document.captureEvents( Event.MOUSEDOWN );       document.onmousedown = clickNS4;    }    else if( document.all && !document.getElementById )     {       document.onmousedown = clickIE4;     }    document.oncontextmenu = new Function( "return( false );");   // -->   </script> 

Applying this effect to a Web page is as simple as pasting the above code into the head of the page.

Here is the new and improved authentication page, which should be placed in the frames page presented above, which is named No_Context_Password.html:

 <html>    <head>      <title>           Password Protected Site       </title>     <script language="JavaScript">      <!--    function clickIE4()     {       if( event.button==2 )       {        return( false );       }   }   function clickNS4(e)    {       if( document.layers || document.getElementById && !document.all )       {        if( e.which == 2 || e.which == 3 )         {          return( false );           }        }    }    if( document.layers )     {       document.captureEvents( Event.MOUSEDOWN );       document.onmousedown = clickNS4;     }     else if( document.all && !document.getElementById )      {       document.onmousedown = clickIE4;      }     document.oncontextmenu = new Function( "return( false );");     function verifyPassword( word )      {         return( word == "sesame" );      }    -->    </script>  </head> <body>   <form action="Continue.html"              onSubmit="JavaScript: return(verifyPassword(this.password.value));">         Please enter your password:&nbsp;       <input type="text" name="password" size="20"><br>      <input type="submit" value="Submit">   </form> </body> </html> 

Excellent, now you have a Web page that prevents the visitor from viewing its source in any way, as when you right-click within the page itself, no menu appears (and if you try and view the source code from the main browser menu, all you see is the source code for the frame container page, which doesn't contain the password information). But wait a minute, is your site now really secure? Read on




JavaScript Professional Projects
JavaScript Professional Projects
ISBN: 1592000134
EAN: 2147483647
Year: 2002
Pages: 130
Authors: Paul Hatcher

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net