0

As per my requirement i have a PDF file to show to the users. But user should not be able to Save it. So, i need to disable the right click option of the browsers. It is working perfectly in Chrome but not working in Mozilla FF or in IE.

here is my code, which is working good in Chrome but not in FF or in IE.

if (document.layers) { 
    document.captureEvents(Event.MOUSEDOWN); 
    document.onmousedown = function () { return false; }; 
} else { 
    document.onmouseup = function (e) { 
        if (e != null && e.type == "mouseup") { //Check the Mouse Button which is clicked. 
            if (e.which == 2 || e.which == 3) { //If the Button is middle or right then disable. 
                return false; 
            } 
        } 
    }; 
} 
document.oncontextmenu = function () { return false; };
gaynorvader
  • 2,619
  • 3
  • 18
  • 32
  • 5
    Don't bother, there's always a way for users to save the file, you just can't prevent it. – Teemu Jul 19 '17 at 08:24
  • if (document.layers) { document.captureEvents(Event.MOUSEDOWN); document.onmousedown = function () { return false; }; } else { document.onmouseup = function (e) { if (e != null && e.type == "mouseup") { //Check the Mouse Button which is clicked. if (e.which == 2 || e.which == 3) { //If the Button is middle or right then disable. return false; } } }; } document.oncontextmenu = function () { return false; }; – user2007550 Jul 19 '17 at 08:26

1 Answers1

1

Try this code

function clickIE() {
    if (document.all) {  //document.all specific to Internet Explorer  
        return false;
    }
}
function clickAll(e) {
    if (document.layers || (document.getElementById && !document.all)) {  //document.layers specific to Netscape
        if (e.which == 2 || e.which == 3) {
            return false;
        }
    }
}
if (document.layers) {
    document.captureEvents(Event.MOUSEDOWN);
    document.onmousedown = clickAll;
} else {
    document.onmouseup = clickAll;
    document.oncontextmenu = clickIE;
}

document.oncontextmenu = new Function("return false")

DEMO

Amal
  • 3,398
  • 1
  • 12
  • 20