![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||||
| |||||
|
|
I am trying to catch mouse position on the entire screen by dynamically generating mouse click event at every 100 ms. |
|
My code only works for IEs but not any Netscape or Gecko-based browsers. |
|
... . And please don't ask me why I am doing this - it is one of functional requirements by all means that I don't know how to explain. |
|
function trackMove(e) { if (arguments.length == 0) e = event; |
|
if (document.layers) { document.f.mX.value = e.pageX; document.f.mY.value = e.pageY; snip |
#2
| |||
| |||
|
|
"punkin" <mclai (AT) mail (DOT) com> wrote in message news:5440be8c.0309191000.1f75e50 (AT) posting (DOT) google.com... I am trying to catch mouse position on the entire screen by dynamically generating mouse click event at every 100 ms. Do you mean "screen" or are you actually just trying to monitor the position of the mouse in the window's viewport or on the HTML page? I don't see any references to screenX/Y event properties in the code below so I think that you cannot mean that want to know the mouse position on the screen. It is important to recognise the distinction between the user's screen (desktop or whatever) and the browser window. My code only works for IEs but not any Netscape or Gecko-based browsers. I don't think that this approach will work on gecko based browsers because you are creating your own event objects (initMouseEvent) and for that you have to provide the mouse XY co-ordinates for the new event object yourself. snip ... . And please don't ask me why I am doing this - it is one of functional requirements by all means that I don't know how to explain. There is a close relationship between your understanding of something and your ability to explain it. Trying to explain things will often make they clearer in your mind so it is worth the effort for that reason alone but in newsgroup postings it is always worth explaining why. Why allows respondents to propose complete alternatives instead of concentrating on trying to fix one approach that may just be fundamentally flawed from the outset. If I wanted to track mouse position for either the viewport or (more likely) the HTML page I would use the document.onmousemove events as a source of that information. But as you will not say why you want to do this I cannot tell if that is appropriate so it is not worth my going into details as to how (though you might groups.google.com search for onmousemove code). snip function trackMove(e) { if (arguments.length == 0) e = event; e = e || event; - or - e = (e)?e:event; - or - if(!e)e = event; if (document.layers) { document.f.mX.value = e.pageX; document.f.mY.value = e.pageY; snip This logic is total nonsense and should be avoided. There is no relationship between a browser implementing a document.layers collection and reading e.pageX instead of e.clientX. It is an assumption and should be avoided unless there is absolutly no alternative. In this case a more useful test would probably be:- if(typeof e.pageX == 'number'){ document.f.mouseX.value = e.pageX; }else{ ... } But pageX/Y and clientX/Y are related but different co-ordinates so on the face of it I don't see this code as providing useable information anyway. I would be inclined to normalise one set of co-ordinates so that the results were either page relative or viewport relative (correcting for clientTop/Left on IE to remove the (default) 2px offset produced by the inner viewport borders). Richard. |
#3
| |||||||
| |||||||
|
|
Yes, I am checking the mouse position on the entire screen regardless of the mouse on the browser window. |
|
The clients won't listen to what I said without trying. They believe that it works for IEs; there must be a way to work for other browsers. Sometimes I just don't know how to explain to them at all. |
|
FYI, the purpose of checking document.layers is to see if the browser is NN4.x. |
|
The code you see is just for testing purpose. They are absolutely correct. |
|
I also thank for another comment about the "e" but I will stick with mine. Because mine will make more sense in the future development when the event handler is getting more complicated. |
|
I will be checking the arguments.length anyway |
|
Otherwise, I will tell the same to my clients - mission impossible - it is really a techical issue. |

#4
| |||
| |||
|
|
mclai (AT) mail (DOT) com (punkin) writes: Yes, I am checking the mouse position on the entire screen regardless of the mouse on the browser window. It is scary that it is even possible in some browsers. I am pretty sure that, e.g., Opera would consider it a security flaw and fix it, so I would not expect it to work in all browsers. The clients won't listen to what I said without trying. They believe that it works for IEs; there must be a way to work for other browsers. Sometimes I just don't know how to explain to them at all. I would say that other browsers consider it a security issue. Would you be able to capture the mouse position over another browser window, containing a document from another domain? That sounds dangerous too. |
#5
| |||
| |||
|
|
mclai (AT) mail (DOT) com (punkin) writes: Yes, I am checking the mouse position on the entire screen regardless of the mouse on the browser window. It is scary that it is even possible in some browsers. I am pretty sure that, e.g., Opera would consider it a security flaw and fix it, so I would not expect it to work in all browsers. snip |
#6
| |||
| |||
|
|
I am not so sure that there is a security issue here. What can you learn from knowing where the mouse is when it is not over the viewport? |
#7
| |||
| |||
|
|
On Sun, 21 Sep 2003 14:37:25 +0100, "Richard Cornford" Richard (AT) litotes (DOT) demon.co.uk> wrote: I am not so sure that there is a security issue here. What can you learn from knowing where the mouse is when it is not over the viewport? You can position a window or other component underneath, or keep your window away from the window, preventing the user from closing (with the mouse) or otherwise interacting with the content - of course there's still other re-courses, but not everyone knows them. |
#8
| |||||
| |||||
|
|
I am not so sure that there is a security issue here. |
|
What can you learn from knowing where the mouse is when it is not over the viewport? |
|
There is also little that can be done with a mouse (assuming that the pointing device is a mouse/trackball and not a pen/touchpad/etc that will just not provide continuous position information) that cannot be done from a keyboard (or with menus). |
|
So even if the desire is to do the impossible and monitor back, refresh and close button activity, knowing that the mouse was over the back button when an unload event happens would not mean that the back button had been used to navigate the page. It could just have easily been Alt+F4 that triggered the unload event, or any number of other things. |
|
It sounds like an effort to solve the wrong problem, but I don't think that we are going to find out why this is being attempted so the real solution will probably not be presented. |
#9
| |||
| |||
|
|
"Lasse Reichstein Nielsen" <lrn (AT) hotpop (DOT) com> wrote in message news:vfrmjrbh.fsf (AT) hotpop (DOT) com... mclai (AT) mail (DOT) com (punkin) writes: Yes, I am checking the mouse position on the entire screen regardless of the mouse on the browser window. It is scary that it is even possible in some browsers. I am pretty sure that, e.g., Opera would consider it a security flaw and fix it, so I would not expect it to work in all browsers. snip I am not so sure that there is a security issue here. What can you learn from knowing where the mouse is when it is not over the viewport? You don't know where the user has positioned their other windows (or, as Ivo points out, how they are stacked), the position/size/etc of the taskbar, the position/size/etc of desktop icons or even the position/size/distribution/etc of chrome in the browser window around the viewport. All are subject to user modification and vary by OS/OS version/Window manager anyway. |
![]() |
| Thread Tools | |
| Display Modes | |
| |