SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why firefox generates 2 clicks for a double click?

    Hello,

    I wonder why firefox generates 2 clicks for a double click. For instance,

    Code:
    <a href="javascript:openPopup();" onDblClick="javascript:someFunc();">click me</a>
    clicking the link should open a popup. Now when I double click not only someFunc() is entered but also the 2 popups are opened. I just added the someFunc() function to test whether ondblclick can stop opening 2 windows. Now it seems not to work at all.This is weird. Why would firefox create 2 popups? Who told it to create 2 popups? For whose benefit? And for my utter inconvenience. Can anybody tell me how can I stop firefox from opening 2 popups when double click event is fired?

  2. #2
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ashim View Post
    I wonder why firefox generates 2 clicks for a double click. For instance,
    Because a double click consists of 2 clicks?

    Quote Originally Posted by ashim View Post
    Why would firefox create 2 popups? Who told it to create 2 popups?
    Presumably you did? href="javascript:openPopup();" triggers openPopup() on click.

  3. #3
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That is quite funny. If double click means 2 clicks then it is self contradictory. Because if double click is a single event then it would be caught in ondblclick event. So it would not fire 2 single click events. Or else if double click is actually 2 single on click events then it would not be caught in the double click event.

    Thus the question whether double click is itself a distinct event or it is the collection of 2 events.

    It is funny to consider double click a collection of 2 single click events. This does not happen with ie. If you deny the existence of double click event then it would be like you double click on an icon in windows explorer and it opens 2 windows to show the contents of the folder. Have you ever seen such behavior?

    I would say this an avaricious behavior of firefox because it wants both the ondblclick and 2 widnows.

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,603
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    When you double click the events it triggers are

    mousedown
    mouseup
    click
    mousedown
    mouseup
    click
    dblclick

    All of those events will perform the requested processing if they have an appropriate handler attached. All browsers are supposed to behave this way - if IE isn't then that is another bug in IE.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Evangelist
    Join Date
    Mar 2006
    Location
    Sweden
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ashim:
    So what you are saying is that if an element has both mousedown and dblclick events attached to it, the browser should wait to fire the mousedown event until it's certain that there is no dblclick event to fire?

  6. #6
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ashim View Post
    It is funny to consider double click a collection of 2 single click events. This does not happen with ie. If you deny the existence of double click event then it would be like you double click on an icon in windows explorer and it opens 2 windows to show the contents of the folder. Have you ever seen such behavior?
    The default behaviour of windows explorer is to open an icon on double click. On single click, it will just select the icon.

    The thing is, that what you want is impossible, since it would involve seeing into the future. Alternatively, you could delay the click event until you're sure that it isn't followed by another click, but that would make your interface noticeable lagging.

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,603
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Windows has in built processing to distinguish between single and double clicks. If you want to distinguish them in a web page you have to code it for yourself.

    Something along the lines of the following should get you started:

    Code:
    onclick="if (clickEvent) clearTimeout(clickEvent); clickEvent = setTimeout('clickfunction',250)"
    ondblclick="clearTimeout(clickEvent);dblclickfunction();"
    That will introduce a 1/4 second delay after the first click to see if it is a part of a double click. Two clicks within that time will trigger dblclickfunction() immediately or if a second click is not received then clickfunction() will be called 1/4 second after the click. Adjust the 250 as required to the length of time you want to wait to test if it is a double click, just don't make it too short or the browser may still recognise a double click when the clicks are too far apart.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •