Connecting Tech Pros Worldwide Forums | Help | Site Map

Event object

Simon Wigzell
Guest
 
Posts: n/a
#1: Jul 23 '05
<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>




Simon Wigzell
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Event object


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.)


Lasse Reichstein Nielsen
Guest
 
Posts: n/a
#3: Jul 23 '05

re: Event object


"Simon Wigzell" <simonwigzell@shaw.ca> writes:
[color=blue]
> 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.)[/color]

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>
---

/L
--
Lasse Reichstein Nielsen - lrn@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Simon Wigzell
Guest
 
Posts: n/a
#4: Jul 23 '05

re: Event object


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.


Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#5: Jul 23 '05

re: Event object


Lasse Reichstein Nielsen wrote:
[color=blue]
> if (typeof Event != "undefined" && window.captureEvents) {[/color]
^^^^^^[color=blue]
> document.captureEvents(Event.CLICK);[/color]
^^^^^^^^[color=blue]
> }[/color]

Typo?


PointedEars
Closed Thread