No Right Click

It used to be quite popular with some web site owners to attempt to prevent access to the context menu that pops up when the right mouse button is clicked. All sorts of convoluted tests involving events such as onclick, onmousedown and so on were produced that attempted to work out which particular button was pressed so as to block the right mouse button while allowing the left one. This was made more complicated by the fact that early browsers did not all follow the same standard as to how the buttons were identified.

None of these scripts were effective. Even in those early browsers that actually allowed the right mouse button to be completely blocked it was still possible to access the context menu via a single key press on the keyboard. What these scripts overlooked is that the right mouse button is not the only way to access the context menu. Most keyboards have a key directly on the keyboard itself that will pop up the context menu for whatever element on the screen currently has the focus. The key is in the bottom right corner of the main section of the keyboard immediately to the left of the right ctrl key and it has a picture of a menu with an arrow pointing to it on the key. Even on keyboards without that key the context menu can be accessed by pressing the shift and F10 keys on the keyboard at the same time.

A much simpler way of detecting accesses to the context menu was introduced into browsers that would not only detect right mouse button presses but also that key on the keyboard. Blocking access to the context menu became a simple matter of adding one line of code to your script:

window.oncontextmenu = function() {return false;};

Now the reason why these web sites wanted to block access to that menu was to prevent the use of one or two of the options in that menu. There are however a number of other options in that menu that provide an alternate way of using the web browser without needing a mouse and in blocking access to the entire menu those web sites were blocking those people who regularly used those options from being able to navigate the web.

With browsers allowing scripts to be saved as favorites/bookmarks so that they can be run against any web page as necessary provided an immediate solution to this problem as the code to disable all attempts at blocking access to the right mouse button involves little more code than the shortest version of the code to block it. If you are still using an antiquated browser that permits access to the context menu to be blocked then simply right click on this link and select to save it to your favorites/bookmarks menu and you will be able to disable any no right click scripts that web sites have attempted to apply. This page doesn't block access to the context menu and so you can easily save the script. If you are curious as to just what the script to disable all no right click scripts looks like then here's the code it uses:


Of course now most browsers either completely disable any attempt to block access to the context menu or they provide an option in the configuration that allows you to choose (and the default is usually to not allow it) and so most people using web browsers today will be completely unaffected by no right click scripts in any web page. The browser will simply prevent such scripts from running and so people will not even know that the site owner was silly enough to try to do such a pointless thing in the first place.


This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow