Click to See Complete Forum and Search --> : can any one help me with this???


noaksey
07-20-2003, 12:36 PM
can any one help me by telling me what the hell is wrong with this?? i just want it to detect whether the broswer is netscape or IE and change the keypress handler as necessary and as that key is pressed close the window. damn javascript i hate it!


<script language="JavaScript" type="text/JavaScript">
function keypress() {
if (navigator.appName == 'Netscape'){
var e = "String.fromCharCode(e.which).toUpperCase()";
}else{
var e = "String.fromCharCode(window.event.keyCode).toUpperCase()";
}

switch (e) {
case T:
window.close();
break;
}
}
window.onKeyDown=keypress;
</script>

i know this is a bit of a mess but cheers if any one can help with this script. noaksey.

Khalid Ali
07-20-2003, 01:02 PM
Replace this

function keypress() {
if (navigator.appName == 'Netscape'){
var e = "String.fromCharCode(e.which).toUpperCase()";
}else{
var e = "String.fromCharCode(window.event.keyCode).toUpperCase()";
}

switch (e) {
case T:
window.close();
break;
}
}
with this

function keypress() {
if (!document.all){
alert("Netscape")
}else{
alert("IE")
}

}