Last active
March 10, 2021 22:15
-
-
Save mosesoak/8831413b1b097315dcc92a090d9d61b5 to your computer and use it in GitHub Desktop.
MSIE Blocker Script (Gatsby)
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
exports.onPreRenderHTML = ({ getHeadComponents, replaceHeadComponents }) => { | |
const headComponents = getHeadComponents(); | |
// Show a blocking message on MSIE | |
// (documentMode is an IE-only property, versions 8-11) | |
// (dangerouslySetInnerHTML keeps the script string unescaped) | |
headComponents.push( | |
<script | |
key="block-msie" | |
type="text/javascript" | |
dangerouslySetInnerHTML={{ | |
__html: `if (typeof window !== 'undefined' && window.document.documentMode) window.onload = function() { document.body.innerHTML = 'Internet Explorer is no longer supported.<br /><br />Please visit this site on Edge or Chrome.'; document.body.style.cssText = 'text-align: center; padding-top: 40vh; font-family: Sans-Serif;'; }`, | |
}} | |
/>, | |
); | |
replaceHeadComponents(headComponents); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment