FAQ : Frequently Asked Questions
FAQ Table of contents
blue line
29. Q:  How can I disable the right mouse for a given HTML page?

A:  You may want to disable the right button of the mouse from the browser, when you have at least one of the following requirements:

  • prevent the page from being reloaded
  • prevent html/javascript source from being displayed
  • prevent images from being copied
In order to achieve this, you must do two things:
  1. Open the page in a new window, taking off the menu bar
    You need to remove the menu bar, because
    • the File option allows to retrieve the page source
    • the Reload/Refresh allows the user to reload the page
    Instead of calling your special page through an <a href="..."> link or through a <form ... >, you must use some JavaScript to load such a page in a new window without the menu bar.
    See the following example, where page /mypath/myspecial.htm is opened in a new window without the menu bar:
    <html>
    <head>
           . . .
    <script type="text/javascript" language="JavaScript">
    //=============================================================
    // opnNoMBar()       Open a window without menu bar
    //=============================================================
    function opnNoMBar(myUrl) {
        nobar=window.open(myUrl,'','scrollbars,resizable,status');
        nobar.focus()
    }
    </script>
           . . .
    </head>
    <body>
           . . .
    <|-- the following line illustrates how to open a window
            without menu bar through an anchor tag: -->
    <a href="javascript:opnNoMBar('/mypath/myspecial.htm')">link
        to my special page</a>
           . . .
    </body></html>
    For further information on opening a new window, see this page.

  2. Disable the right mouse
    This is easily done by adding the following to the <body ...> tag:
    oncontextmenu="return false" .

  3. What about some menu bar of yours?
    In some circumstances, you would like to have a menu bar of yours to let users print the page, go back one page, etc.
    Here is an example of how you may implement this:
    print previous page next page
    through the following HTML
    <table border=1 bordercolor=#006699 bgcolor=#99ccff>
    <tr><td>
    <table border=0 bgcolor=#99ccff cellspacing=5>
    <tr><td><a href="javascript:window.print()">
            <img src="/cgidev/print.gif" alt="print" border=0></a>
            </td>
        <td><a href="javascript:history.go(-1)">
            <img src="/cgidev/prvpag.gif" alt="previous page" border=0></a>
            </td>
        <td><a href="javascript:history.go(+1)">
            <img src="/cgidev/nxtpag.gif" alt="next page" border=0></a>
            </td></tr>
    </td></tr></table>
    </td></tr></table>
blue line