< Day Day Up > |
Tired of too-clever web developers disabling right-click on images? Reenable the full functionality of your browser. Somewhere along the line, web developers got the impression that it was their Web. Unstoppable pop-up windows and scrolling status bar text were bad enough, but the stupid web trick that really drove me nuts was the way some sites tried to disable the right-click context menu. If I tried to right-click on an image, the site would pop up an alert saying that they had helpfully disabled that feature in a pathetic attempt to prevent me from saving the image to my hard drive or viewing it in a separate window. Well, as you already know from using Firefox and Greasemonkey, it is most definitely your Web. This hack reenables the right-click context menu by nullifying all the JavaScript event handlers that sites use to try to disable it. 9.2.1. The CodeThis user script runs on all pages. However, because it is so aggressive in trying to disable the disablers, it ends up breaking some sites that use those particular event handlers for different purposes. Google, for example, uses onmousedown handlers (in a good way) on Gmail and Google Maps. Those sites are excluded by default. If you find other problematic sites, you can add them to the exclusion list in the Manage User Scripts dialog [Hack #3]. Save the following user script as antidisabler.user.js: // ==UserScript== // @name Anti-Disabler // @namespace http://diveintomark.org/projects/greasemonkey/ // @description restore context menus on sites that try to disable them // @include * // @exclude http*://mail.google.com/* // @exclude http://maps.google.com/* // ==/UserScript== with (document.wrappedJSObject || document) { onmouseup = null; onmousedown = null; oncontextmenu = null; } var arAllElements = document.getElementsByTagName('*'); for (var i = arAllElements.length - 1; i >= 0; i--) { var elmOne = arAllElements[i]; with (elmOne.wrappedJSObject || elmOne) { onmouseup = null; onmousedown = null; oncontextmenu = null; } } 9.2.2. Running the HackBefore installing the user script, go to http://www.dynamicdrive.com/dynamicindex9/noright2.htm. This is a page that demonstrates a particularly nasty right-click disabler script. Right-clicking on either image produces an alert that the function is disabled, as shown in Figure 9-1. Figure 9-1. Dynamic Drive site with context menu disabledNow, install the user script from Tools Install This User Script, and refresh the page. Right-clicking on either image bypasses the alert altogether and displays the standard image context menu, as shown in Figure 9-2. Figure 9-2. Dynamic Drive site with context menu restoredIf you find that this hack is interfering with too many sites you use (like Gmail), you can take a whitelist approach by including no sites by default, and then add individual sites (like Dynamic Drive) as you find them. |
< Day Day Up > |