tag set using JavaScript in IE 8? I am implementing a JavaScript function that enables / disa...">

Why doesn't the "disabled" property of the <link> tag set using JavaScript in IE 8?

I am implementing a JavaScript function that enables / disables two CSS files on a website:

function switch_style ()
{
    var i, link_tag ;
    for (i = 0, link_tag = document.getElementsByTagName("link"); i < link_tag.length ; i++ ) 
    {
        if ((link_tag[i].rel.indexOf( "stylesheet" ) != -1) && link_tag[i].title) 
        {
            if(link_tag[i].title == "normal")
            {
                link_tag[i].disabled = true;
            }
            else if (link_tag[i].title == "contrast")
            {
                link_tag[i].disabled = false;
            }
        }
    }
    set_cookie( style_cookie_name, "contrast", style_cookie_duration );
}

As you can see, I enable or disable the link tag. This works in all browsers, but not in IE8.

Is there a known reason?

+3
source share
2 answers

You will switch the property of the disabledelements link. As the MDC says,

[t] its attribute is non-standard and is used only by some Microsoft browsers and should not be used by authors . To achieve the effect, use one of the following methods:

  • disabled , <link>;
  • disabled , DOM .

link DOM, element.removeChild.

: link , JavaScript :

javascript:(function(){var a=document.getElementsByTagName('head')[0];a.removeChild(a.getElementsByTagName('link')[0])})();

( SO, :)

+4

, removeAttribute('disabled') , false?

0

Source: https://habr.com/ru/post/1772390/


All Articles