Click to See Complete Forum and Search --> : dynamically adding onmouseup to body


Ulukai
12-13-2002, 02:00 PM
Hi,

I want to add an onMouseUp-Event to the body tag. (IE 5.x)
It is important for me, that this is not done in the html-file but in an js file. I tried to do something like this:

var body = document.getElementsByTagName("body")[0];
body.onMouseUp = myOnMouseUp;

where myOnMouseUp is a valid function.
This works fine with the event onMouseDown but not with onMouseUp (with Netscape-Navigator it works but not with IE5.x)... can you help me or explain why?

Thx in advance

Ulukai

ShrineDesigns
12-13-2002, 03:05 PM
this will probably do it

var myBody = document.getElementById('isBody');
myBody.onMouseUp = myOnMouseUp;

you should you onFocus or onBlur
the body doesn't have a onMouse or a onClick event
when you add [0] to the body element it getting the first element in the body array

gil davis
12-13-2002, 03:53 PM
if (!document.all)
{document.captureEvents(Event.MOUSEUP);}
document.onmouseup = myUp;
function myUp() {
alert("Up!");
}

Tested in IE 5.5, NS 4.8 and NS 6.2.

Ulukai
12-14-2002, 08:22 AM
Thanks that worked fine.
As I looked over my code, I discovered the real error, the problem is solved now.
CU

Ulukai