css 'pointer-events' property alternative for IE

前端 未结 12 1258
無奈伤痛
無奈伤痛 2020-11-22 02:45

I have a drop down navigation menu in which some of the title should not navigate to other page when clicked(these title open a drop down menu when clicked on) while others

相关标签:
12条回答
  • 2020-11-22 03:42

    I've found another solution to solve this problem. I use jQuery to set the href-attribute to javascript:; (not ' ', or the browser will reload the page) if the browser window width is greater than 1'000px. You need to add an ID to your link. Here's what I'm doing:

    // get current browser width
    var width = $(window).width();
    if (width >= 1001) {
    
        // refer link to nothing
        $("a#linkID").attr('href', 'javascript:;'); 
    }
    

    Maybe it's useful for you.

    0 讨论(0)
  • 2020-11-22 03:45

    Use OnClientClick = "return false;"

    0 讨论(0)
  • 2020-11-22 03:46

    You can also just "not" add a url inside the <a> tag, i do this for menus that are <a> tag driven with drop downs as well. If there is not drop down then i add the url but if there are drop downs with a <ul> <li> list i just remove it.

    0 讨论(0)
  • 2020-11-22 03:47

    Best solution:

    .disabled{filter: alpha(opacity=50);opacity: 0.5;z-index: 1;pointer-events: none;}
    

    Runs perfectly on all browsers

    0 讨论(0)
  • 2020-11-22 03:49

    It's worth mentioning that specifically for IE, disabled=disabled works for anchor tags:

    <a href="contact.html" onclick="unleashTheDragon();" disabled="disabled">Contact</a>
    

    IE treats this as an disabled element and does not trigger click event. However, disabled is not a valid attribute on an anchor tag. Hence this won't work in other browsers. For them pointer-events:none is required in the styling.

    UPDATE 1: So adding following rule feels like a cross-browser solution to me

    UPDATE 2: For further compatibility, because IE will not form styles for anchor tags with disabled='disabled', so they will still look active. Thus, a:hover{} rule and styling is a good idea:

    a[disabled="disabled"] {
            pointer-events: none; /* this is enough for non-IE browsers */
            color: darkgrey;      /* IE */
        }
            /* IE - disable hover effects */   
            a[disabled="disabled"]:hover {
                cursor:default;
                color: darkgrey;
                text-decoration:none;
            }
    

    Working on Chrome, IE11, and IE8.
    Of course, above CSS assumes anchor tags are rendered with disabled="disabled"

    0 讨论(0)
  • 2020-11-22 03:51

    I faced similar issues:

    1. I faced this issue in a directive, i fixed it adding a as its parent element and making pointer-events:none for that

    2. The above fix did not work for select tag, then i added cursor:text (which was what i wanted) and it worked for me

    If a normal cursor is needed you could add cursor:default

    0 讨论(0)
提交回复
热议问题