Hello Guys,
Wanna to disable the right click? Follow the below JavaScript to achieve that.
eg.
test.html
<html>
<body>
<div id='img'>
<div id='img'>
<%= image_tag('https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiH4hixyVqT9hmPJ3J2xBoC7972VOGveRP864H_eGjWZyeIrzxVdHs3GgshxDAS0LdvmtzFBmSxNw8yC3Plz7zUH2fE594sKTp2FTvbaITKcM1ajz8u8GTTMbol3KXUJLs5NPtdfLqc_A/s220-h/cutex.jpeg') %>
</div>
</body>
</body>
<script language="javascript" type="text/javascript">
// Disable right click
var message = "you can't right click on image";
function clickIE4(){
if (event.button == 2) {
return false;
}
}
function clickNS4(e){
if (document.layers || document.getElementById && !document.all) {
if (e.which == 2 || e.which == 3) {
return false;
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown = clickNS4;
}
else
if (document.all && !document.getElementById) {
document.onmousedown = clickIE4;
}
document.oncontextmenu = new Function("alert(message); return false")
// Disable right click
var message = "you can't right click on image";
function clickIE4(){
if (event.button == 2) {
return false;
}
}
function clickNS4(e){
if (document.layers || document.getElementById && !document.all) {
if (e.which == 2 || e.which == 3) {
return false;
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown = clickNS4;
}
else
if (document.all && !document.getElementById) {
document.onmousedown = clickIE4;
}
document.oncontextmenu = new Function("alert(message); return false")
</script>
</html>
No comments:
Post a Comment