Skip to content

Commit

Permalink
FIX: browser-update should work with old browsers (#12436)
Browse files Browse the repository at this point in the history
This caused issues in IE10 / IE11 with compatibility mode.
  • Loading branch information
udan11 committed Mar 18, 2021
1 parent 5024ea7 commit da1e37d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
app/assets/javascripts/browser-update.js
app/assets/javascripts/discourse-loader.js
app/assets/javascripts/env.js
app/assets/javascripts/main_include_admin.js
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ config/locales/**/*.yml
!config/locales/**/*.en*.yml
script/import_scripts/**/*.yml

app/assets/javascripts/browser-update.js
app/assets/javascripts/discourse-loader.js
app/assets/javascripts/env.js
app/assets/javascripts/main_include_admin.js
Expand Down
20 changes: 11 additions & 9 deletions app/assets/javascripts/browser-update.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
//browser-update.org notification script, <browser-update.org>
//Copyright (c) 2007-2009, MIT Style License <browser-update.org/LICENSE.txt>

/* eslint-disable no-var */

(function () {
let $buo = function () {
var $buo = function () {
// Sometimes we have to resort to parsing the user agent string. :(
if (navigator && navigator.userAgent) {
let ua = navigator.userAgent;
var ua = navigator.userAgent;

// we don't ask Googlebot to update their browser
if (
Expand All @@ -22,10 +24,10 @@
}

document.getElementsByTagName("body")[0].className += " crawler";
let mainElement = document.getElementById("main");
let noscriptElements = document.getElementsByTagName("noscript");
var mainElement = document.getElementById("main");
var noscriptElements = document.getElementsByTagName("noscript");
// find the element with the "data-path" attribute set
for (let i = 0; i < noscriptElements.length; ++i) {
for (var i = 0; i < noscriptElements.length; ++i) {
if (noscriptElements[i].getAttribute("data-path")) {
// noscriptElements[i].innerHTML contains encoded HTML
if (noscriptElements[i].childNodes.length > 0) {
Expand All @@ -36,21 +38,21 @@
}

// retrieve localized browser upgrade text
let t = I18n.t("browser_update"); // eslint-disable-line no-undef
var t = I18n.t("browser_update"); // eslint-disable-line no-undef
if (t.indexOf(".browser_update]") !== -1) {
// very old browsers might fail to load even translations
t =
'Unfortunately, <a href="https://www.discourse.org/faq/#browser">your browser is too old to work on this site</a>. Please <a href="https://browsehappy.com">upgrade your browser</a> to view rich content, log in and reply.';
}

// create the notification div HTML
let div = document.createElement("div");
var div = document.createElement("div");
div.className = "buorg";
div.innerHTML = "<div>" + t + "</div>";

// create the notification div stylesheet
let sheet = document.createElement("style");
let style =
var sheet = document.createElement("style");
var style =
".buorg {position:absolute; z-index:111111; width:100%; top:0px; left:0px; background:#FDF2AB; text-align:left; font-family: sans-serif; color:#000; font-size: 14px;} .buorg div {padding: 8px;} .buorg a, .buorg a:visited {color:#E25600; text-decoration: underline;} @media print { .buorg { display: none !important; } }";

// insert the div and stylesheet into the DOM
Expand Down

0 comments on commit da1e37d

Please sign in to comment.