简体   繁体   中英

IntersectionObserver Polyfill won't load in IE11

I am using IntersectionObserver and have a polyfill that should load if the browser isn't compatible. Unfortunately, things aren't working in IE11. In console, I can see an error that IntersectionObserver is undefined. I'd expect this if I wasn't loading the polyfill, but I should be! I checked the network tab, and it doesn't seem like IE ever downloaded the polyfill script. Any ideas why? Here's my code that should check whether the browser supports IntersectionObserver and loads the polyfill if it doesn't

<script type="text/javascript">
if (!('IntersectionObserver' in window)) {
    var script = document.createElement("script");
    script.src = "https://raw.githubusercontent.com/w3c/IntersectionObserver/master/polyfill/intersection-observer.js";
    document.getElementsByTagName('head')[0].appendChild(script);
}
</script>

I try to test your code on my side with IE 11 and chrome browser.

I notice that IE 11 downloads the intersection-observer.js file without any issue.

在此处输入图片说明

I suggest you to clear the cache and again try to make a test.

you can also try to enable the option Always refresh from server in network tab.

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