Skip to content

Instantly share code, notes, and snippets.

@joshuafredrickson
Created June 25, 2021 15:05
Show Gist options
  • Save joshuafredrickson/c6d502781884f8655a9ce22b2653a9a8 to your computer and use it in GitHub Desktop.
Save joshuafredrickson/c6d502781884f8655a9ce22b2653a9a8 to your computer and use it in GitHub Desktop.
Redirect IE11 to Edge automatically
/**
* Detect IE11 and open the current window in Edge instead
*/
if (
navigator.userAgent.indexOf('MSIE') !== -1 ||
navigator.appVersion.indexOf('Trident/') > -1
) {
// Redirect to Edge
window.location = 'microsoft-edge:' + window.location.href;
// Close the current window
setTimeout(function () {
window.open('', '_self', '').close();
}, 0);
}
@joshuafredrickson
Copy link
Author

Using the microsoft-edge: protocol in IE11 will open the link in Edge automatically, essentially forcing the user to view the site in Edge if it's installed. This could concept could be fleshed out into a modal window with link instead depending on the site's needs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment