Skip to content
Search

JavaScript:Example:DisableRightMouseButton

lastmod 2024-11-06created 2022-04-044 edits

A so-called "copy protection" feature. Removes the right mouse button menu.

JavaScript Code

The JavaScript code is as follows:

const omitformtags = ["input", "textarea", "select"].join("|");

function disableselect(e) {
    if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1) {
        return false
    }
}

function reEnable(){
    return true
}

if (typeof document.onselectstart!="undefined") {
    document.onselectstart = new Function ("return false");
} else {
    document.onmousedown = disableselect;
    document.onmouseup = reEnable;
}

Turning it back on

Conversely, if you want to remove this feature, remove the related scripts.

In the Console tab of Chrome's developer mode, opened with F12:

window.oncontextmenu = null;
document.oncontextmenu = null;

Loop version over all tags:

for(var id = 0; id < document.getElementsByTagName("*").length; ++id) { elements[id].oncontextmenu = null; }

For reference, it didn't work in firefox...

See also

author Zer0 sitemap