Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > How to define whether the left mouse button is pressed in Firefox

Reply
Thread Tools

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

 
 
marss
Guest
Posts: n/a
 
      04-16-2007
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>

 
Reply With Quote
 
 
 
 
Daz
Guest
Posts: n/a
 
      04-16-2007
On Apr 16, 4:38 pm, "marss" <(E-Mail Removed)> wrote:
> 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.

 
Reply With Quote
 
 
 
 
marss
Guest
Posts: n/a
 
      04-17-2007

Daz wrote:

> 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.

 
Reply With Quote
 
marss
Guest
Posts: n/a
 
      04-17-2007

Randy Webb wrote:

>
> 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...

 
Reply With Quote
 
Daz
Guest
Posts: n/a
 
      04-17-2007
On Apr 17, 1:42 pm, Randy Webb <(E-Mail Removed)> wrote:
> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
tricky+frustrating: changing mouse handler while mouse pressed doesn't work Claus Atzenbeck Java 1 11-26-2004 09:40 AM
How to detect that a key is being pressed, not HAS been pressed earlier!?? Rune Python 6 01-29-2004 12:39 PM
If value in name field in top row disable submit button until add button is pressed or field is cleared. Chuck Javascript 0 11-10-2003 02:23 AM
Mouse movement while a button is pressed Jeroni Paul Javascript 2 09-04-2003 11:25 PM



Advertisments