It shows that you are unregistered. Please register with us by clicking Here
![]() |
|
![]() |
![]() | Register - FAQ - Today's Posts - New Posts - Support - Search | ![]() |
|
|
#2 (permalink) |
|
Member
Join Date: Jul 2006
Age: 48
Posts: 45
|
If we assume that the object position is the same as the cursor postion. Then we can use the standard method to find the cursor's position relative to the entire page is via the pageX and pageY properties of the event object. Internet Explorer doesn't support these properties, but it does include some properties that almost the one we want. clientX and clientY are available in Internet Explorer, though they measure the distance from the mouse cursor to the edge of the browser window. In order to find the position of the cursor relative to the entire page, we need to add the current scroll position to these dimentions. To do this we need to use getScrollingPosition function from that solution to retrive the required dimentions.
e.g function displayCursorPosition(event) { if (typeof event == "undefined") { event = windows.event; } var scrollingPosition=getScrollingPosition(); var cursorPosition = [0, 0]; if (typeof event.pageX != "undefined" && typeof event.x != "undefined") { cursorPosition[0] = event.pageX; cursorPosition[1] = event.pageY; } else { cursorPosition[0] = event.clientX + scrollingPosition[0]; cursorPosition[1] = event.clientY + scrollingPosition[1]; } var paragraph = document.getElementByTagName("p")[0]; paragraph.replaceChild(document.createTextNode( "Your mouse is currently located at : "+cursorPosition[0] + ","+cursorPosition[1], paragraph.firstChild); return true; } clientX/clientY are valid W3C DOM event properties that exist in most browsers, so we can't rely on their existance as an indication that we need to use them. Instead, within our event handler, we test for the existance of pageX. Internet Explorer for Mac does have pageX, but it's an incorrect value, so we must also check for x.x is actually a nonstandard property, but most browsers support it ( the exception being Opera 8+ and Internet Explorer). It's ok that Opera 8+ doesn't support x, because the else statement is actually a cross-browser method for calculating the mouse cursor position except in Safari, which incorrectly gives clientX the same value as pageX. That's why we still need to use both methods of calculting the cursor position. |
|
|
|
|
|
#3 (permalink) |
|
Senior Member
Join Date: Sep 2006
Age: 22
Posts: 460
|
Which browsers will that code work in - assuming the browsers have JavaScript on? I worry about using JavaScript because it can have such different results in various browsers.
__________________
|
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| What are the events of connection object? | agaba175 | ASP | 0 | 08-05-2006 08:44 PM |
| What is files collection in the folder object? | agaba175 | ASP | 0 | 08-05-2006 08:39 PM |
| What method of the Server object do you need to use to obtain an instance of the- | agaba175 | ASP | 0 | 08-05-2006 08:29 PM |
| What new object in ASP3.0 can be used to gather information about the last - | agaba175 | ASP | 0 | 08-05-2006 08:27 PM |
| Waht does the connection object do? | agaba175 | ASP | 0 | 08-05-2006 08:07 PM |