Click to See Complete Forum and Search --> : event handling in netscape4


arup13
01-18-2003, 07:33 AM
i seem to be having some probs working out how to handle evnts in netscape4.
viz:

function handler(e){
swapImg('...img_name...');
}


function addhandler(o){
o.onmouseover = handler;
o.onmouseout = handler;
}

function init(){
if(document.all || document.getElementById){
var img = document.images;
img['outlook'].onmouseover = function() {swapImg('outlook');}
img['outlook'].onmouseout = function() {imgRestore('outlook');}
img['befriending'].onmouseover = function() {swapImg('befriending');}
img['befriending'].onmouseout = function() {imgRestore('befriending');}
img['employment'].onmouseover = function() {swapImg('employment');}
img['employment'].onmouseout = function() {imgRestore('employment');}
img['run'].onmouseover = function() {swapImg('run');}
img['run'].onmouseout = function() {imgRestore('run');}
}
else if(document.layers){
addhandler(document.images['...img_name...']);
}
}

window.onload = init;

the code works fine for ie5+ and nn6, however, when i try and use it in nn4, i get a message telling me that object o has no properties.
i really cant figure this out.
or understand what the error message means. any advice?
i followed the flanagan procedure of adding handlers to the events in his event handler script.
no joy.
do i need to use captureEvents(event.MOUSEOVER etc) to initially capture the event? tried this but obviously i am told onload that there is no event associated with the capture.

khalidali63
01-18-2003, 07:39 AM
you need to tell NS 4 to capture events

if(document.layers){
document.captureEvents(Event.MOUSEOVER)
document.captureEvents(Event.MOUSEOUT)
}

hope this helps

arup13
01-19-2003, 09:59 PM
and that's it?
so inserting that code will capture all events in the document.. but how will i specify when an event occurs over the image?

presumably, as the image is contained in <layer></layer> tags i could cature events related to that layer right?
thus

layer.captureEvents(Event.MOUSEOVER)

etc

am fuzzy tho on how to return that to a variable.
with IE its easy

var e = window.event

allowing you to read the event propperties from that.

well i suppose it must be the same for nn? var e = layer.captureEvents(Event.MOUSEOVER) ??

so if an event occurs over the layer, it'll then trigger the handler, which as its all 1.2 code could still be organised with the code for IE and nn6, thus:

o.onmouseover = function() {......}

would still be applicable for nn4.

eh, right?