Disabling Right Click on Web Page/DIV, Disabling Text Copy From a Web Page

Here are few JavaScript code snippets that can be useful on your web pages if you want to diasable right click on your page or on a particular div. You can also disable text selection on your page. Just have a look.
Source:http://amiteighty82.blogspot.com/2011/01/disabling-right-click-on-web-page_19.html



Disabling right click on web page:

Just paste the code snippets in your Head tag

<script LANGUAGE="JavaScript">
document.oncontextmenu=new Function ("return false");
</script>

Disabling right click on a particular div:

<script LANGUAGE="JavaScript">
document.getElementById('div1').oncontextmenu=new Function ("return false")
</script



Disabling Text copy and right clicks:

<script language="JavaScript">
<!-- Disable
function disableselect(e){
return false
}
function reEnable(){
return true
}
//if IE4+
document.onselectstart=new Function ("return false")
document.oncontextmenu=new Function ("return false")
//if NS6
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
//-->

Written by Arvind Bhardwaj

Arvind is a certified Magento 2 expert with more than 10 years of industry-wide experience.

Website: http://www.webspeaks.in/

5 thoughts on “Disabling Right Click on Web Page/DIV, Disabling Text Copy From a Web Page

Comments are closed.