PDA

View Full Version : Netscape Issues


Phil_at _work
09-05-2002, 01:27 AM
OK the Key Launcher works in IE but not inside of Netscape. It stopped working when I added to the code,

The below code was written so that I could include a Form in the the same page that I had included the Key Launcher this way when the user hits a defined key it doesn't navigate away if a defined key is pressed.

Problem is the key launcher doesn't work in Netscape now. I adopted the Key Launcher from another site and added the check to see if you are in a form.

JavaScript Error:
event is not defined.

-----------------------------CODE SNIP------------------------------

function checkKey(keypress)
{
var sourceTag;
var key = new Array();

sourceTag=event.srcElement.tagName;

if(sourceTag=="INPUT"||sourceTag=="TEXTAREA"||sourceTag=="OPTION")

{



}else{


key['c'] = "#content";
key['n'] = "#main_nav";
key['s'] = "#section_nav";
key['t'] = "index.htm";
key['h'] = "help.htm";

isNetscape=(document.layers);
eventChooser = (isNetscape) ? keyStroke.which : event.keyCode;
which = String.fromCharCode(eventChooser).toLowerCase();

for

(var i in key) if (which == i) window.location = key[i];
}

}

document.onkeypress = checkKey;

-----------------------------CODE SNIP------------------------------
Thanks in advance.

Phil

joh6nn
09-05-2002, 04:21 AM
in NS4, the key events are very unreliable, especially, the keypress event. the keyup and keydown events are a bit more reliable, but not very.

in general, NS4 can't be counted on, in my experience ( limited, to say the least) to support these.

adios
09-05-2002, 04:40 AM
Nothing wrong with NS4 - you've referenced the (window.)event object, which doesn't exist there. This function is a bit of a mess; here:

<html>
<head>
<title>untitled</title>
<script type="text/javascript" language="javascript">

function checkKey(e) {
var key = new Object();
var sourceEl = window.event ? event.srcElement : e && e.target ? e.target : null;
if (sourceEl) {
if (sourceEl.type == 'text' || sourceEl.type == 'textarea') return true;
else {
key['c'] = "#content";
key['n'] = "#main_nav";
key['s'] = "#section_nav";
key['t'] = "index.htm";
key['h'] = "help.htm";
var eventChooser = (document.layers) ? e.which : event.keyCode;
var which = String.fromCharCode(eventChooser).toLowerCase();
for (var i in key) if (which == i) alert(key[i])//window.location = key[i];
}
}
}

document.onkeypress = checkKey;

</script>
</head>
<body>
<form>
<input type="text">
</form>
</body>
</html>

Phil_at _work
09-05-2002, 05:00 AM
:thumbsup: Thankyou works a treat :thumbsup: