by
583 8
0
3
317
1
Top 10% !
Popular
Specified
No tags for this snippet yet.
BrowserSafari
LanguageJavaScript
SourceGitHub
SourceMyGists

Safari 10.1 `nomodule` support

Safari 10.1 `nomodule` support: 
safari-nomodule.js
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/3512366/Safari-10-1--nomodule--support?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
/** * Safari 10.1 supports modules, but does not support the `nomodule` attribute - it will * load <script nomodule> anyway. This snippet solve this problem, but only for script * tags that load external code, e.g.: <script nomodule src="nomodule.js"></script> * * Again: this will **not** prevent inline script, e.g.: * <script nomodule>alert('no modules');</script>. * * This workaround is possible because Safari supports the non-standard 'beforeload' event. * This allows us to trap the module and nomodule load. * * Note also that `nomodule` is supported in later versions of Safari - it's just 10.1 that * omits this attribute. */ (function() { var check = document.createElement('script'); if (!('noModule' in check) && 'onbeforeload' in check) { var supportModule = false; document.addEventListener('beforeload', function(e) { if (e.target === check) { supportModule = true; } else if (e.target.hasAttribute('nomodule') && supportModule) { e.preventDefault(); } }, true); check.type = 'module'; check.src = '.'; document.head.appendChild(check); check.remove(); } }());
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus