简体   繁体   中英

Every other click of link in Internet Explorer does not work

I have noticed that when clicking a link in IE that has the href set to a javascript function, the first click will work but the second click sometimes won't. The third will work and the fourth won't. In other words, IE will only trigger the javascript function on every other click. If you put a long pause between clicking it will trigger the function every time. But as you click just a little faster, it will skip every other click. Has anyone else noticed this behavior? I do not get the same behavior in Firefox.

Here is some sample code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>Test</title>
        <script type="text/javascript">
        var count = 0;
        function doClick()
        {
            count++;
            document.frm.COUNTER.value = count;
        }
    </script>
</head>
<body>
    <form name="frm" action="">
        <input name="COUNTER" value="0"/>
        <a href="javascript:doClick();">Click Here</a>
    </form>
</body>
</html>

Click very slowly and it increments the counter every time. Click at even a moderately faster pace and it skips clicks. This also happens with the onclick and onmousedown events of controls in IE6/7/8.

The reason why this is an issue is because the application is a Point of Sale system and we are implementing on screen keys for a touchscreen. Having to press a link/button/key more than once because you are typing too fast is not going to be acceptable.

You're probably experiencing double-click events instead.

<a href="" onclick="doClick();return false;" ondblclick="doClick();return false;">

That should do the trick.

As far as I can tell IE's event handlers just seem to be slower than other browsers.

http://jsfiddle.net/F5B54/

I tested this in Firefox,Chrome, and IE8. IE definitely ran slower/missed clicks.

I don't have IE9 installed but it should be better than IE8.

--- Updated Answer ---

IE handles a onclick and dblclick separately. Meaning if you click twice quickly this will register as single dblclick event.

Chrome on the other hand will register 2 onclick events AND a dbl click event.

Mixing click and double click for a single element can therefore result in drastically different behavior across browsers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM