Hello to all, welcome to therichpost.com. In this post, I will tell you How to disable control u, control s with javascript? Some people want to secure their code, even me also so with this javascript code, we can little bit secure our valuable code from copy makers.
Here you can you can check the code to disable control u, control s with javascript:
Here is the code you need to add this into body tag:
<body onkeypress=”return disableCtrlKeyCombination(event);” onkeydown=”return disableCtrlKeyCombination(event);”>
Here is the script code:
<script>
function disableCtrlKeyCombination(e)
{
//List of keys
var forbiddenKeys = new Array(‘u’, ‘s’);
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 check if other key is in forbidenKeys array
if(isCtrl)
{
for(i=0; i<forbiddenKeys.length; i++)
{
//case-insensitive comparation
if(forbiddenKeys[i].toLowerCase() == String.fromCharCode(key).toLowerCase())
{
//alert(‘Key combination CTRL + ‘+String.fromCharCode(key) +’ has been disabled.’);
return false;
}
}
}
return true;
}
</script>
There are so many tricky code in javascript and I will let you know all. Please do comment if you any query related to this post. Thank you. Therichpost.com
Recent Comments