java-soft
08-17-2005, 01:18 PM
Hi
I use this code to block function keys (F5) . It work but cursor focus on the file upload field it not work. Can you help me.
Thank.
CODE :
/************************
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>--- F5 BLOCK ---</title>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620">
</head>
<script language="javascript">
var msg = 'That functionality is restricted.';
var asciiF5 = 116;
//==============================================================//
if(document.all){ //ie has to block in the key down
document.onkeydown = onKeyPress;
}
else if (document.layers || document.getElementById){ //NS and mozilla have to block in the key press;
document.onkeypress = onKeyPress;
}
function onKeyPress(evt) {
window.status = '';
//get the event object
var oEvent = (window.event) ? window.event : evt;
//hmmm in mozilla this is jacked, so i have to record these seperate what key was pressed
var nKeyCode = oEvent.keyCode ? oEvent.keyCode :oEvent.which ? oEvent.which : void 0;
var bIsFunctionKey = false;
/*hmmm in mozilla the keycode would contain a function key ONLY IF the charcode IS 0
else key code and charcode read funny, the charcode for 't'
returns 116, which is the same as the ascii for F5
SOOO,... to check if a the keycode is truly a function key,
ONLY check when the charcode is null OR 0, IE returns null, mozilla returns 0
*/
if(oEvent.keyCode==asciiF5){
bIsFunctionKey = asciiF5;
}
//convert the key to a character, makes for more readable code
var sChar = String.fromCharCode(nKeyCode).toUpperCase();
//get the active tag that has the focus on the page, and its tag type
var oTarget = (oEvent.target) ? oEvent.target : oEvent.srcElement;
var sTag = oTarget.tagName.toLowerCase();
var sTagType = oTarget.getAttribute("type");
var bRet = true; //assume true as that will be the case most times
if(sTagType != null){
sTagType = sTagType.toLowerCase();
}
if(bIsFunctionKey){ // Capture and stop these keys
bRet = false;
}
if(!bRet){
try{
oEvent.returnValue = false;
oEvent.cancelBubble = true;
if(document.all){ //IE
oEvent.keyCode = 0;
}else{ //NS
oEvent.preventDefault();
oEvent.stopPropagation();
}
window.status = msg;
}catch(ex){
//alert(ex);
}
}
return bRet;
}
</script>
<body>
Test Block Key F5
<br>
<form action="" method="post" enctype="multipart/form-data" name="form1">
<p>
<input type="text" name="textfield">
<input type="checkbox" name="checkbox" value="checkbox">
<input name="radiobutton" type="radio" value="radiobutton">
<input type="reset" name="Reset" value="Reset">
<br>
<select name="select">
<option value="dsdsf">dsfds</option>
<option value="sdfds">sfdsfs</option>
</select>
<br>
<textarea name="textarea" cols="50"></textarea>
<br>
<input type="file" name="file">
</p>
<p>
<select name="select" size="5">
<option value="1">123456789</option>
<option value="2">12345678910</option>
<option value="3">12345678911</option>
<option value="4">12345678912</option>
<option value="5">12345678913</option>
<option value="6">12345678914</option>
</select>
</p>
</form>
</body>
</html>
/*********************************
reference site :
http://www.faqts.com/knowledge_base/view.phtml/aid/32261
I use this code to block function keys (F5) . It work but cursor focus on the file upload field it not work. Can you help me.
Thank.
CODE :
/************************
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>--- F5 BLOCK ---</title>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620">
</head>
<script language="javascript">
var msg = 'That functionality is restricted.';
var asciiF5 = 116;
//==============================================================//
if(document.all){ //ie has to block in the key down
document.onkeydown = onKeyPress;
}
else if (document.layers || document.getElementById){ //NS and mozilla have to block in the key press;
document.onkeypress = onKeyPress;
}
function onKeyPress(evt) {
window.status = '';
//get the event object
var oEvent = (window.event) ? window.event : evt;
//hmmm in mozilla this is jacked, so i have to record these seperate what key was pressed
var nKeyCode = oEvent.keyCode ? oEvent.keyCode :oEvent.which ? oEvent.which : void 0;
var bIsFunctionKey = false;
/*hmmm in mozilla the keycode would contain a function key ONLY IF the charcode IS 0
else key code and charcode read funny, the charcode for 't'
returns 116, which is the same as the ascii for F5
SOOO,... to check if a the keycode is truly a function key,
ONLY check when the charcode is null OR 0, IE returns null, mozilla returns 0
*/
if(oEvent.keyCode==asciiF5){
bIsFunctionKey = asciiF5;
}
//convert the key to a character, makes for more readable code
var sChar = String.fromCharCode(nKeyCode).toUpperCase();
//get the active tag that has the focus on the page, and its tag type
var oTarget = (oEvent.target) ? oEvent.target : oEvent.srcElement;
var sTag = oTarget.tagName.toLowerCase();
var sTagType = oTarget.getAttribute("type");
var bRet = true; //assume true as that will be the case most times
if(sTagType != null){
sTagType = sTagType.toLowerCase();
}
if(bIsFunctionKey){ // Capture and stop these keys
bRet = false;
}
if(!bRet){
try{
oEvent.returnValue = false;
oEvent.cancelBubble = true;
if(document.all){ //IE
oEvent.keyCode = 0;
}else{ //NS
oEvent.preventDefault();
oEvent.stopPropagation();
}
window.status = msg;
}catch(ex){
//alert(ex);
}
}
return bRet;
}
</script>
<body>
Test Block Key F5
<br>
<form action="" method="post" enctype="multipart/form-data" name="form1">
<p>
<input type="text" name="textfield">
<input type="checkbox" name="checkbox" value="checkbox">
<input name="radiobutton" type="radio" value="radiobutton">
<input type="reset" name="Reset" value="Reset">
<br>
<select name="select">
<option value="dsdsf">dsfds</option>
<option value="sdfds">sfdsfs</option>
</select>
<br>
<textarea name="textarea" cols="50"></textarea>
<br>
<input type="file" name="file">
</p>
<p>
<select name="select" size="5">
<option value="1">123456789</option>
<option value="2">12345678910</option>
<option value="3">12345678911</option>
<option value="4">12345678912</option>
<option value="5">12345678913</option>
<option value="6">12345678914</option>
</select>
</p>
</form>
</body>
</html>
/*********************************
reference site :
http://www.faqts.com/knowledge_base/view.phtml/aid/32261