Event object

S

Simon Wigzell

<html>

I pulled the following code off the internet. The idea is to intercept
various user screen events. IOn this case it would just return the x y
location of the cursor when the mouse is clicked in an alert. It doesn't run
for me - I get "Event is undefined" error message. What's up?

<script language="JavaScript">
window.captureEvents(Event.CLICK);
window.onclick= displayCoords;
function displayCoords(e) {
alert("x: " + e.pageX + " y: " + e.pageY);
}
</script>
 
S

Simon Wigzell

snip

I see now that this example only works in navigator. Does anyone know of a
more generalized function that will account for all browsers? (By "all" I
mean IE and Netscape 5 or better and those that follow their protocols, I
don't care if it doesn't work for someone using something totally obscure or
old and out of date, I'll have a special message saying "bite me" for them.)
 
L

Lasse Reichstein Nielsen

Simon Wigzell said:
Does anyone know of a more generalized function that will account
for all browsers? (By "all" I mean IE and Netscape 5 or better and
those that follow their protocols, I don't care if it doesn't work
for someone using something totally obscure or old and out of date,
I'll have a special message saying "bite me" for them.)

Since I use a browser that you seem to consider "obscure", I am *very*
tempted to just say "bite me".

Anyway, try this:
---
<script type="text/javascript">
if (typeof Event != "undefined" && window.captureEvents) {
document.captureEvents(Event.CLICK);
}
document.onclick = function (evt) {
evt = evt || window.event;
if (typeof evt.pageX == "number") {
var pageX = evt.pageX;
var pageY = evt.pageY;
} else {
var root = document.compatMode == "CSS1Compat" ?
document.documentElement :
document.body;
pageX = evt.clientX + root.scrollLeft;
pageY = evt.clientY + root.scrollTop;
}
alert("x: " + pageX + " y: " + pageY);
}
</script>
 
S

Simon Wigzell

snip

Thanks, I thought I could use events to catch when the mouse was released
from the scroll bar but that doesn't register. I'm still looking for a way
to detect that event.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top