Quantcast
Channel: DIGCMS » Uncategorized
Viewing all articles
Browse latest Browse all 15

How to disable right and control click on link

$
0
0

Use the following javascript code and add into your html file

<script>
var isNS = (navigator.appName == "Netscape") ? 1 : 0;
if(navigator.appName == "Netscape") document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);
function mischandler(){
return false;
}
function mousehandler(e){
var myevent = (isNS) ? e : event;
var eventbutton = (isNS) ? myevent.which : myevent.button;
if((eventbutton==2)||(eventbutton==3)) return false;
}
document.oncontextmenu = mischandler;
document.onmousedown = mousehandler;
document.onmouseup = mousehandler;

//disable control+click
function disableCtrlKeyClick(e)
{
 var key;
 var isCtrl;

if(window.event)
 {
 key = window.event.keyCode; //IE
 if(window.event.ctrlKey)
 isCtrl = true;
 else
 isCtrl = false;
 }
 else
 {
 key = e.which; //firefox
 if(e.ctrlKey)
 isCtrl = true;
 else
 isCtrl = false;
 }

//if ctrl is pressed dont open the link in new tab
 if(isCtrl)
 {
 e.preventDefault();
 return false;
 }
 return true;
}
</script>

In HTML file use following code

<a herf="http://google.com" onclick="disableCtrlKeyClick(event)" >google.com </a>
How to disable right and control click on link

How to disable right and control click on link

The post How to disable right and control click on link appeared first on DIG into CMS.


Viewing all articles
Browse latest Browse all 15

Trending Articles