-
Notifications
You must be signed in to change notification settings - Fork 0
/
ienotwelcome.js
97 lines (82 loc) · 3.19 KB
/
ienotwelcome.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
89
90
91
92
93
94
95
96
97
/*
* ienotwelcome.js, version 1.1
* Copyright 2009 Nicholas Firth-McCoy
* http://nfm.id.au/projects/ienotwelcome
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Do not remote this copyright notice.
*
*/
// Politely tell the user to get a standards compliant browser
function getARealBrowser() {
// Customize notification appearance here
var backgroundColor = "#63849F";
var color = "#333333";
var position = "fixed";
var bottom = "0";
var right = "0";
var width = "auto";
var padding = "0.5em 1em";
var border = "1px solid #3B699F";
var id = 'ieNotWelcome';
// Message to display (inserted using innerHTML, so you can specify HTML here for links, images etc)
var message = "Web page broken? <a style='color: white;' href='http://getfirefox.com'>Get a real web browser!</a>";
var div = document.createElement('div');
div.id = id;
// If this is IE6/7
if (div.style.setAttribute) {
div.style.setAttribute('cssText', "position: " + position + "; bottom: " + bottom + "; right: " + right + "; width: " + width + "; padding: " + padding + "; background-color: " + backgroundColor + "; color: " + color + "; border: " + border + ";");
// If this browser uses the correct method
} else {
div.setAttribute('style', "position: " + position + "; bottom: " + bottom + "; right: " + right + "; width: " + width + "; padding: " + padding + "; background-color: " + backgroundColor + "; color: " + color + "; border: " + border + ";");
}
// Set the div's content to the variable 'message'
div.innerHTML = message;
// Add the notification to the page
document.body.appendChild(div);
}
// Check whether the user's browser sucks
function browserSucks() {
// Should all versions of IE be rejected?
var allVersionsSuck = false;
// If allVersionsSuck is false, what minimum version of IE doesn't suck?
var minimumIEVersion = 8;
var appVer = navigator.appVersion.toLowerCase();
var isIE, IEVersion, versionPos;
// Determine if the user's browser is IE
if (appVer.indexOf('msie') != -1) {
isIE = true;
};
// If the user's browser is IE
if (isIE) {
// If allVersionsSuck is true, the user's browser sucks
if (allVersionsSuck == true) {
return true;
}
// Determine IE's version number
versionPos = appVer.indexOf('msie');
IEVersion = parseInt(parseFloat(appVer.substring(versionPos + 5, appVer.indexOf(';', versionPos))));
// If IE's version is less than the minimum allowed version, the user's browser sucks
if (IEVersion < minimumIEVersion) {
return true;
}
}
// Otherwise, the user's browser doesn't suck
return false;
}
// The fun starts here
if (browserSucks()) {
getARealBrowser();
}