Saturday, November 23, 2019

Block Right Click Access to Context Menus on Web Pages

Block Right Click Access to Context Menus on Web Pages Web novices often believe that by blocking their visitors use of the mouse right-click context menu that they can prevent the theft of their web page content. Nothing could be further from the truth. Disabling right clicks is easily sidestepped by more savvy users, and the ability to access much of a web pages code itself is a basic feature of web browsers that doesnt require a right click at all. Drawbacks There are many ways to bypass the no right click script, and in reality the only effect that such a script has is to annoy those of your visitors who legitimately use the the right-click context menu (as that menu is properly called) in their web navigation. Additionally, all of the scripts that I have seen to do this only block access to the context menu from the right mouse button. They dont consider the fact that the menu is also accessible from the keyboard. All anyone needs to do to access the menu using a 104 key keyboard is to select the object on the screen for which they want to access the context menu (for example by left clicking on it) and then press the context menu key on their keyboard- its the one immediately to the left of the right CTRL key on PC keyboards. On a 101 key keyboard, you can execute a right-click command by holding down the shift key and pressing F10. JavaScript If you would like to disable right-clicks on your web page anyway, heres a really simple JavaScript that you can use to block all access to the context menu (not just from the right mouse button but from the keyboard as well)- and really annoy your visitors. This script is even simpler than most of the ones that only block the mouse button, and it works in about as many browsers as those scripts do. Heres the entire script for you: body oncontextmenureturn false; Adding just that small piece of code to the body tag of your web page is more effective at blocking your visitors access to the context menu than the many no-right-click scripts that you can find elsewhere on the web because it blocks access from both the mouse button and from keyboard options described above. Limitations Of course, the script doesnt work in all web browsers (e.g., Opera ignores it- but then Opera ignores all of the other no-right-click scripts as well). This script also does nothing to prevent your visitors from accessing the page source using the View Source option from their browser menu, or from saving the web page and viewing the source of the saved copy in their favorite editor. And finally, though you may disable access to the context menu, that access can be easily re-enabled by users simply by typingjavascript:void oncontextmenu(null) into the address bar of the browser.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.