How to define whether the left mouse button is pressed in Firefox

M

marss

Hi,
How can I define in Firefox whether the left mouse button is pressed
when I move mouse over a html element?
The documentation says that "e.button == 0 for standard 'click',
usually left button"
http://developer.mozilla.org/en/docs/DOM:event.button
Tracing of mouse clicks or mousedown/mouseup events looks not
reliable, because mouse can be pressed elsewhere out of the html
element (even outside of the browser) and then move over the html
element.
Maybe exists a better way to do it?

Here the test that reproducing the problem.
<head>
<script type="text/javascript">
function test(e)
{
if (e.button == 0)
document.getElementById("d").innerHTML = "Left mouse button is
pressed";
}
</script>
</head>
<body>
<div onmousemove="test(event)" style="height:50px;background-
color:gray"></div>
<div id="d"></div>
</body>
 
D

Daz

Hi,
How can I define in Firefox whether the left mouse button is pressed
when I move mouse over a html element?
The documentation says that "e.button == 0 for standard 'click',
usually left button"http://developer.mozilla.org/en/docs/DOM:event.button
Tracing of mouse clicks or mousedown/mouseup events looks not
reliable, because mouse can be pressed elsewhere out of the html
element (even outside of the browser) and then move over the html
element.
Maybe exists a better way to do it?

Here the test that reproducing the problem.
<head>
<script type="text/javascript">
function test(e)
{
if (e.button == 0)
document.getElementById("d").innerHTML = "Left mouse button is
pressed";}

</script>
</head>
<body>
<div onmousemove="test(event)" style="height:50px;background-
color:gray"></div>
<div id="d"></div>
</body>

I think you are along the right lines. Personally. I would add an
onmouseover and onmouseout event to the elements in question. The
event will attach and dettach an onclick handler to the element when
you have moved the mouse over, which will test to see if the left
button was clicked.

I hope this helps.

Daz.
 
M

marss

Daz said:
I think you are along the right lines. Personally. I would add an
onmouseover and onmouseout event to the elements in question. The
event will attach and dettach an onclick handler to the element when
you have moved the mouse over, which will test to see if the left
button was clicked.

I hope this helps.

Daz.

It is to be regretted that only way to determine mouse buttons state
in Firefox is calculating of clicks. :(
Thanks for the answer.
 
M

marss

Randy said:
That won't tell you though. If I move outside the browser, hold down the
left mouse button, move over your div, move outside the browser window
again, release the mouse button and then mouse back over your element,
how would it know what state the mouse is in?

You are right. I see that the situation is rather sad. But I have to
do something. As I said before it is not reliable but lacking
something better...
 
D

Daz

That won't tell you though. If I move outside the browser, hold down the
left mouse button, move over your div, move outside the browser window
again, release the mouse button and then mouse back over your element,
how would it know what state the mouse is in?

This is very true, but unfortunately, as all browsers only monitor
events within the window, without an external API, it would be
impossible to achieve the exact results we'd like. If the mouse
buttons are clicked or released outside of the window, it won't
register the button state within the browser, (or can it the button
state be worked out onmousemove?).

Also, remember that the div isn't meant to detect when the button is
down, but rather, when the button is clicked on top of it. If you
click on a blank spot in your browser window, and hold the button
down, then drag your mouse over something that's clickible outside of
the browser window, such as your start menu, the start menu doesn't
open up just because the mouse is down. It has to be explicitly
clicked for the start menu to open. Obviously, you can drag files into
it, but they must be from the operating system itself, and not from
within an application that doesn't tie in quite heavily to the inner
workings of the OS. Basically, I guess that what I am saying, is that
there's a bridge between browser and OS, unless of course the browser
has been made to specifically work as part of the core OS. I
completely agree with what you've said, but we can only do the best we
can with the tools we have to hand. We cannot always acheive the
impossible with the low level user-functionality, that most modern
applications tend to provide us with, as they are intended to be used
by "average" users and be quite secure against idiots/accidents.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top