473,396 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Event object

<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
4 1263
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
"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
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
Lasse Reichstein Nielsen wrote:
if (typeof Event != "undefined" && window.captureEvents) { ^^^^^^ document.captureEvents(Event.CLICK); ^^^^^^^^ }


Typo?
PointedEars
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andy Read | last post by:
Hello all, I have the requirement to produce source code that produces an object hierarchy. Example: Root | Folder 1
18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
0
by: BlueMonkMN | last post by:
I've been trying to think of the right way to design relationships between objects with different desired lifetimes that raise events. If an event source is a relatively permanent object and the...
1
by: Rohit Raghuwanshi | last post by:
Hello all, we are running a delphi application with DB2 V8.01 which is causing deadlocks when rows are being inserted into a table. Attaching the Event Monitor Log (DEADLOCKS WITH DETAILS) here....
13
by: Charles Law | last post by:
Mr "yEaH rIgHt" posted the following link about a week ago in answer to my question about removing event handlers. > http://www.vbinfozine.com/t_bindevt.shtml Following on from that post, the...
41
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based...
15
by: prabhdeep | last post by:
Hi, Can somebody explain, why in following code, i get "event not defined" error funcTest(sMenu) { doument.getElementById('id1').addEventListener('mousedown', function(){ click(sMenu,...
6
by: Murray Hopkins | last post by:
Hi. THE QUESTION: How do I get a reference to my Object when processing an event handler bound to an html element ? CONTEXT: Sorry if it is a bit long. I am developing a JS calendar tool....
6
by: TriFuFoos | last post by:
Hi there, I was wondering if anyone knew if/how to assign an event to a global variable? I tried to do it and IE 7 came back with an error saying "Member not found" My code looked similar to...
4
by: tshad | last post by:
I am just getting started with events and had a couple of questions on why they do what they do. If you have a textbox and you want to handle an event you can just do: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.