-
Notifications
You must be signed in to change notification settings - Fork 0
/
Find_IE.js
88 lines (69 loc) · 3.09 KB
/
Find_IE.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
================================================================================
=========================== script created by: =============================
=========================== Jack Reinieren =============================
=========================== Date: 1 november 2016 =============================
================================================================================
================================================================================
===================== What does this script do? ================================
=== This script checks if a user uses IE 11 to browse to some site. ===
=== If the user does indeed uses IE 11, then a custom message is displayed, ===
=== along with a list of compatible browsers and a link to the downloadpages ===
=== of the browsers. A working example can be found here: ===
=== http://www.maxifusion.nl/agenda.html (Site is in Dutch) ===
================================================================================
*/
/* Function checks if the browser in use is IE 11,
If IE11 is in use, the function returns true,
else, it returns false. */
function msieversion() {
var ua = window.navigator.userAgent;
var old_ie = ua.indexOf('MSIE ');
var new_ie = ua.indexOf('Trident/');
if ((old_ie > -1) || (new_ie > -1)) {
return true
} else {
return false
}
};
// This function to create a list of browsers:
function makeUL(array) {
// Create the list element:
var list = document.createElement('ul');
for(var i = 0; i < array.length; i++) {
// Create the list item:
var item = document.createElement('li');
// Set its contents:
item.appendChild(array[i]);
// Add it to the list:
list.appendChild(item);
};
// Finally, return the constructed list:
return list;
};
// Function to use when the browser is in fact IE11
function IECompat () {
var ShowDataEl = document.getElementById("ShowData"); // <-- this is a div, you can change this to suite your needs
var AllBrowsers = [];
var Browsers = {
Titles: ["Chrome", "FireFox", "Opera", "Edge"],
Hrefs: ['https://www.google.com/chrome/browser/desktop/index.html', 'https://www.mozilla.org/nl/firefox/new/', 'http://www.opera.com/nl', "https://www.microsoft.com/nl-nl/windows/microsoft-edge"]
};
// create an array for the downloadlinks.
for (var i=0; i < Browsers.Titles.length; i++) {
var a = document.createElement('a');
var linkText = document.createTextNode(Browsers.Titles[i]);
a.appendChild(linkText);
a.title = linkText;
a.href = Browsers.Hrefs[i];
AllBrowsers.push(a)
};
var node = document.createTextNode('<CUSTOM MESSAGE> (eg: You can download one of these great other browsers:) ');
ShowDataEl.appendChild(node)
ShowDataEl.appendChild(makeUL(AllBrowsers));
};
/* You can use this in your script, to check if IE 11 is in fact, in use
if (msieversion()) {
IECompat()
}
*/