Skip to content

Instantly share code, notes, and snippets.

@timelf123
Created March 17, 2014 17:39
Show Gist options
  • Save timelf123/9604321 to your computer and use it in GitHub Desktop.
Save timelf123/9604321 to your computer and use it in GitHub Desktop.
// Disable Context Menu
document.oncontextmenu = function () {
    return false
};

// Disable dragging of HTML elements
document.ondragstart = function () {
    return false
};

// Break out of frames
function bust() {
    document.write = "";
    window.top.location = window.self.location;
    setTimeout(function () {
        document.body.innerHTML = ''
    }, 0);
    window.self.onload = function (evt) {
        document.body.innerHTML = ''
    }
}
if (window.top !== window.self) {
    try {
        if (window.top.location.host) {} else {
            bust()
        }
    } catch (ex) {
        bust()
    }
}

// Annoy user if context menu button presssed
document.onkeydown = function (e) {
    if (e.keyCode == 93) {
        alert('_')
    }
};

// Disable selecting of text
document.onselectstart = function () {
    if (event.srcElement.type != "text" && event.srcElement.type != "textarea" && event.srcElement.type != "password") {
        return false
    } else {
        return true
    }
};

// Disable Mousedown event, except for text-areas & Inputs where it's needed
document.onmousedown = function (e) {
    var obj = e.target;
    if (obj.tagName.toUpperCase() == "INPUT" || obj.tagName.toUpperCase() == "TEXTAREA" || obj.tagName.toUpperCase() == "PASSWORD") {
        return true
    } else {
        return false
    }
};

// Stop CTRL Key abuse on your page!
window.onkeydown = function (e) {
    if (e.ctrlKey == true) {
        return false
    }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment