By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,400 Members | 1,368 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,400 IT Pros & Developers. It's quick & easy.

Event object

P: n/a
<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>

Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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.)
Jul 23 '05 #2

P: n/a
"Simon Wigzell" <si**********@shaw.ca> writes:
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>
---

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #3

P: n/a
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.
Jul 23 '05 #4

P: n/a
Lasse Reichstein Nielsen wrote:
if (typeof Event != "undefined" && window.captureEvents) { ^^^^^^ document.captureEvents(Event.CLICK); ^^^^^^^^ }


Typo?
PointedEars
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.