Skip to content

Commit 826f3f3

Browse files
authored
Browser: Add alert for unsupported version (#436)
1 parent 85d0a15 commit 826f3f3

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
navigator.browserVersion = (() => {
2+
var ua = navigator.userAgent;
3+
var tem;
4+
var M =
5+
ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) ||
6+
[];
7+
if (/trident/i.test(M[1])) {
8+
tem = /\brv[ :]+(\d+)/g.exec(ua) || [];
9+
return 'IE ' + (tem[1] || '');
10+
}
11+
if (M[1] === 'Chrome') {
12+
tem = ua.match(/\b(OPR|Edge)\/(\d+)/);
13+
if (tem != null) return tem.slice(1).join(' ').replace('OPR', 'Opera');
14+
}
15+
M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?'];
16+
tem = ua.match(/version\/(\d+)/i);
17+
if (tem != null) M.splice(1, 1, tem[1]);
18+
return M.join(' ');
19+
})();
20+
21+
const currentBrowser = navigator.browserVersion.split(' ').at(0);
22+
const currentVersion = navigator.browserVersion.split(' ').at(1);
23+
24+
// Minimum version for FULL support. Source - https://caniuse.com/css-nesting
25+
const supportedNestedCSSVersion = {
26+
Safari: 17.2,
27+
Chrome: 112,
28+
Firefox: 117,
29+
Opera: 106,
30+
};
31+
32+
// Set the alert if first time visiting
33+
if (!localStorage.getItem('isBrowserVersionChecked')) {
34+
if (currentVersion < supportedNestedCSSVersion[currentBrowser]) {
35+
alert(
36+
`Unsupported browser\n\n${currentBrowser} ${currentVersion} may not display this site correctly.\nUpdate to at least ${currentBrowser} ${supportedNestedCSSVersion[currentBrowser]} for the best experience.`
37+
);
38+
}
39+
localStorage.setItem('isBrowserVersionChecked', true);
40+
}

layouts/partials/scripts.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
{{ $codecopyv2 := resources.Get "/js/code-copy-v2.js" | fingerprint "sha512" }}
33
<script src="{{ $codecopyv2.RelPermalink }}" type="text/javascript"></script>
44

5+
<!-- load browser incompatibility js -->
6+
{{ $browserIncompatibility := resources.Get "/js/browser-incompatibility.js" | fingerprint "sha512" }}
7+
<script src="{{ $browserIncompatibility.RelPermalink }}" type="text/javascript"></script>
8+
59
<!-- load site dropdown js -->
610
{{ $siteDropdown := resources.Get "/js/site-dropdown.js" | fingerprint "sha512" }}
711
<script src="{{ $siteDropdown.RelPermalink }}" type="text/javascript"></script>

0 commit comments

Comments
 (0)