Disabled button is clickable on Edge browser

后端 未结 4 1873
轻奢々
轻奢々 2020-12-20 17:06

I have problem with Edge browser. In my web site I have buttons with span tags inside them. In this span tags I bind text and icons. So far I had no problem but on Edge brow

相关标签:
4条回答
  • 2020-12-20 17:51

    One work around I've come up with using angularjs is inspired by Ben Nadel's blog here

    So for example:

    angular.module('myModule').directive(
        "span",
        function spanDirective() {
            return ({
                link: function (scope, element, attributes) {
                    element.bind('click', function (e) {
                        if (e.target.parentNode.parentNode.disabled || e.target.parentNode.disabled) {
                            e.stopPropagation();
                        }
                    })
                },
                restrict: "E",
            });
        }
    );
    
    0 讨论(0)
  • 2020-12-20 18:05

    Just set

    pointer-events: none;

    for disabled buttons.

    Here's CSS to disable all disabled elements everywhere:

    *[disabled] {
        pointer-events: none !important;
    }
    

    pointer-events documentation

    0 讨论(0)
  • 2020-12-20 18:05

    This is a bug in Microsoft Edge. Disabled buttons accept clicks if they contain any HTML elements (i.e. if they contain anything else than just text).

    Reported multiple times via Microsoft Connect:

    • Event bubbles from child element into element (by SO user Ryan Joy)
    • Bootstrap/Jquery disabled buttons generate click events and show tooltips even disabled

    The bug was still present in Build 10565 (16 October 2015). It was fixed in the November update, Build 10586.


    A possible (but ugly) workaround is to call some Javascript in onclick for every button, which then checks if the button is disabled and returns false (thus suppressing the click event).

    0 讨论(0)
  • 2020-12-20 18:11

    Since you're not always going to be using a span element and probably don't want to create a new directive for every element type, a more general workaround would be to decorate the ngClick directive to prevent the event from reaching the real ngClick's internal event handler when the event is fired on a disabled element.

    var yourAppModule = angular.module('myApp');
    // ...
    yourAppModule.config(['$provide', function($provide) {
        $provide.decorator('ngClickDirective', ['$delegate', '$window', function($delegate, $window) {
            var isEdge = /windows.+edge\//i.test($window.navigator.userAgent);
    
            if (isEdge) {
                var directiveConfig = $delegate[0];
                var originalCompileFn = directiveConfig.compile;
    
                directiveConfig.compile = function() {
                    var origLinkFn = originalCompileFn.apply(directiveConfig, arguments);
    
                    // Register a click event handler that will execute before the one the original link
                    // function registers so we can stop the event.
                    return function linkFn(scope, element) {
                        element.on('click', function(event) {
                            if (event.currentTarget && event.currentTarget.disabled) {
                                event.preventDefault();
                                event.stopPropagation();
                                event.stopImmediatePropagation();
                            }
                        });
    
                        return origLinkFn.apply(null, arguments);
                    };
                };
            }
    
            return $delegate;
        }]);
    }]);
    
    0 讨论(0)
提交回复
热议问题