I've got a website which was built using Jekyll. It doesn't render correctly in IE 8, therefore, I want a way to detect if they are using IE 8 and display an appropriate page / alert.
I've got a function which detects the browser and replaces the page displayed:
"use strict";
define([], function () {
function ieVersion() {
var myNav = navigator.userAgent.toLowerCase();
return (myNav.indexOf('msie') != -1) ? parseInt(myNav.split('msie')[1]) : -1;
}
var v = ieVersion();
if (ieVersion() > -1) {
document.location.replace("ie8.html");
}
});
I am calling it within the HEAD tag:
<!DOCTYPE html>
<html class='no-js' lang='en'>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>{{ page.title }}</title>
<meta content='width=device-width, initial-scale=1.0' name='viewport'>
<link href='http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic|Droid+Serif:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<link href='{{ site.url }}/css/framework.css' rel='stylesheet'>
<link href='{{ site.url }}/css/syntax.css' rel='stylesheet'>
<link href='{{ site.url }}/css/style.css' rel='stylesheet'>
<link href='{{ site.url }}/css/fontello.css' rel='stylesheet'>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script src='{{ site.url }}/js/IE.js'></script>
<script src='{{ site.url }}/js/modernizr.js'></script>
</head>
However, it doesnt appear to work.
I opened it within IE8 and there is a error saying:
'$' is undefined
IE.js