JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 25th, 2001, 08:33 AM
Statik Statik is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Posts: 130 Statik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 25 m 5 sec
Reputation Power: 13
Question Mouse x,y coords in Javascript?

Is there a way to retrieve the x,y coordinates of the mouse in Javascript? I'm not looking for a coodinate stream, just the x,y onclick(). It's going to be my target for a DHTML flyout.

Reply With Quote
  #2  
Old June 25th, 2001, 09:05 AM
Void Void is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: The Netherlands
Posts: 200 Void User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
Send a message via ICQ to Void
If you want to do this in IE:

http://www.webcoder.com/howto/artic...demo=0,source=0

If you want to do this in NN:

No idea. Probably not supported, as usual.

Reply With Quote
  #3  
Old June 25th, 2001, 11:00 AM
Statik Statik is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Posts: 130 Statik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 25 m 5 sec
Reputation Power: 13
Actually, you can do this in both IE and Netscape. The variables are:

IE:
window.event.clientX, and windows.event.clientY

Netscape:
e.pageX and e.pageY

Reply With Quote
  #4  
Old June 25th, 2001, 07:10 PM
Blue Angel Blue Angel is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Posts: 22 Blue Angel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Actually Void there is a way for NS, and Statik you're missing something.

<script language="javascript">
function getMousePos(e) { //you need the 'e', although it does NOT need to be defined
//NS
if (document.layers||document.getElementById&&!document.all) {
alert(e.pageX+"and"+e.pageY)
}
//IE
else if (document.all) {
form1.X.value=window.event.clientX
form1.Y.value=window.event.clientY
}
}

if(!window.captureEvents) document.onmousemove=getMousePos
if (window.captureEvents) {
window.captureEvents(Event.MOUSEMOVE)
window.onmousemove=getMousePos //e should not be defined
}
</script>
<body>
<form name="form1">
<input name="X" value="">
<input name="Y" value="">
</form>
</body>

This should do it! In NS you can't use the form, because you can't change the value of the form, for some reason. Hope it helps!

Reply With Quote
  #5  
Old June 25th, 2001, 09:27 PM
adios adios is offline
Senior Citizen
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2001
Location: leftcoast
Posts: 2,019 adios User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 15
function getMousePos(e) {
//NS
if (document.layers||document.getElementById&&!document.all) {
document.form1.X.value = e.pageX
document.form1.Y.value = e.pageY
}
//IE
else if (document.all) {
form1.X.value = event.clientX
form1.Y.value = event.clientY
}
}

Don't call alert()s in a loop!

Use status as an alternative.

e is the event object, passed automatically with property assignment (window.onmousemove=getMousePos); if you're calling handlers from HTML, gotta pass it yer own self...Netscape 6 supports pageX & Y properties, but also provides DOM standard clientX & Y as well.
http://www.brainjar.com/dhtml/events/default4.asp

cheers,adios

Last edited by adios : June 25th, 2001 at 10:03 PM.

Reply With Quote
  #6  
Old June 26th, 2001, 09:15 AM
DJdrenaline DJdrenaline is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2001
Location: Toronto, Ontario, Canada
Posts: 631 DJdrenaline User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 19 sec
Reputation Power: 12
*This is Blue Angel*

LOL, Adios, I didn't know how to access the forms... so all I could think of was to alert it. It's easy to get out of though. Put your mouse at the top of the screen and push enter

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Mouse x,y coords in Javascript?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap