<html>
<head>
<script language="JavaScript">
function disableCtrlKeyCombination(e)
{
//list all CTRL + key combinations you want to disable
var forbiddenKeys = new Array('a','c','v');
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())
{
return false;
}
}
}
return true;
}
function disableSelection()
{
if (document.body.onselectstart!="undefined") //IE route
document.body.onselectstart=function(){return false}
else if (document.body.style.MozUserSelect!="undefined") //Firefox route
document.body.style.MozUserSelect="none"
else //All other route (ie: Opera)
document.body.onmousedown=function(){return false}
document.body.style.cursor = "default"
}
</script>
</head>
<body OnKeyDown = "return disableCtrlKeyCombination(event);">
this is a new page.
<script type="text/javascript" language="JavaScript">
disableSelection()
</script>
</body>
</html>
<head>
<script language="JavaScript">
function disableCtrlKeyCombination(e)
{
//list all CTRL + key combinations you want to disable
var forbiddenKeys = new Array('a','c','v');
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())
{
return false;
}
}
}
return true;
}
function disableSelection()
{
if (document.body.onselectstart!="undefined") //IE route
document.body.onselectstart=function(){return false}
else if (document.body.style.MozUserSelect!="undefined") //Firefox route
document.body.style.MozUserSelect="none"
else //All other route (ie: Opera)
document.body.onmousedown=function(){return false}
document.body.style.cursor = "default"
}
</script>
</head>
<body OnKeyDown = "return disableCtrlKeyCombination(event);">
this is a new page.
<script type="text/javascript" language="JavaScript">
disableSelection()
</script>
</body>
</html>
No comments:
Post a Comment