<script language="JavaScript">
function disableCtrlKeyCombination(e)
{
//list all CTRL + key combinations you want to disable
var forbiddenKeys = new Array("a", "s", "c");
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>
<body onkeypress="return disableCtrlKeyCombination(event);" onkeydown="return disableCtrlKeyCombination(event);" >
</body>
function disableCtrlKeyCombination(e)
{
//list all CTRL + key combinations you want to disable
var forbiddenKeys = new Array("a", "s", "c");
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>
<body onkeypress="return disableCtrlKeyCombination(event);" onkeydown="return disableCtrlKeyCombination(event);" >
</body>
nice
ReplyDeletei will put this to my blog
thaks
Still i can save by pressing Ctrl + s in browser.
DeleteSTEP : click in link of address bar and press Ctrl + s
Is there any permanent way to prevent Ctrl + s to save the HTML page ??
Thank you very much, sorry for spelling errors bad English know your code helped me a lot! Once again thank you very much!
ReplyDeleteStill i can save by pressing Ctrl + s in browser.
DeleteSTEP : click in link of address bar and press Ctrl + s
Is there any permanent way to prevent Ctrl + s to save the HTML page ??
same issue here, please help!
Deletevery usefull ,, thanks
ReplyDeleteNice information Shared.
ReplyDeleteRegards,
Swapnil
I have a problem tooo..
ReplyDeletei can save the file using cltr+s
Any help??
Very Useful Code for Security Purpose.
ReplyDeleteThank you for sharing this code very useful to my blog..
ReplyDeleteBalita Ngaun
Still i have the same issue. Ctrl + S key is not prevented when the dropdown is open.
ReplyDeleteAny idea?