Last active
December 16, 2015 02:19
-
-
Save OllyHodgson/5361889 to your computer and use it in GitHub Desktop.
Test for IE legacy Filters and Transitions support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Test if this install of IE supports legacy Filters and Transitions | |
Needed because Filters and Transitions can be disabled under IE's security | |
settings ("Binary and Script Behaviors" under the "ActiveX controls and | |
plug-ins" category). This is often done on corporate windows installations | |
"for security reasons". They'll fail silently (or error if you try to access | |
the element's filter collection in js). This setting also disables VML. | |
See: | |
http://paintincode.blogspot.co.uk/2012/06/css-opacity-ie-filter-binary-and-script.html | |
Returns true if it detects support, false if not. | |
*/ | |
function detectIEfiltersupport () { | |
var supportsIEfilters = false, | |
el = document.body.appendChild(document.createElement("div")), | |
probe = 0; | |
/* Try to set a filter on the div, then access the div's filters collection. | |
IE throws an error here if filters are disabled, so supportsIEfilters will | |
remain false. */ | |
try { | |
el.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=50)"; | |
probe = el.filters.length; | |
supportsIEfilters = true; | |
} catch (err) { | |
/* In legacy IE, err will be "Unspecified error" if filters are disabled. Newer browsers | |
shouldn't have an el.filters so it'll be a reference error (undefined). */ | |
/* console.log("Error: ", err); */ | |
} | |
el.parentNode.removeChild(el); | |
return supportsIEfilters; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment