TRiG
TRiG

Reputation: 10643

Browser Update Script

Browser-Update.org provides a nice piece of javascript which alerts users of out-of-date browsers to update them. Unfortunately (a) IE7 is not included in the default list of out-of-date browsers, and (b) the script doesn't work over SSL.

The script they suggest is

<script type="text/javascript"> 
var $buoop = {} 
$buoop.ol = window.onload; 
window.onload=function(){ 
 try {if ($buoop.ol) $buoop.ol();}catch (e) {} 
 var e = document.createElement("script"); 
 e.setAttribute("type", "text/javascript"); 
 e.setAttribute("src", "http://browser-update.org/update.js"); 
 document.body.appendChild(e); 
} 
</script> 

Instead, I'm using external javascript as follows:

app.onload(function() {
    if ('https:' === document.location.protocol) return; // Browser Update script is not currently available over SSL.
    var $buoop = {vs:{i:7,f:2,o:10.5,s:2,n:9}};
    var e = document.createElement('script');
    e.setAttribute('type', 'text/javascript');
    e.setAttribute('src', 'http://browser-update.org/update.js');
    document.body.appendChild(e);
});

To be clear: app.onload() is a nice function which adds functions to the window.onload handler.

This seems to work, but there's an unfortunate side-effect. If the alert is dismissed, it shouldn't show again in that browsing session. With the script above, that doesn't seem to work. On IE7, the alert happens on each page load. Is there a way around that?

Upvotes: 1

Views: 3509

Answers (2)

Mircea Soaica
Mircea Soaica

Reputation: 2817

you could save a cookie when the alert is shown and check every time if that cookie exists before showing the alert.

Upvotes: 1

rlemon
rlemon

Reputation: 17666

var _shown = false;
app.onload(function() {
if(!_shown) {
    if ('https:' === document.location.protocol) return; // Browser Update script is not currently available over SSL.
    var $buoop = {vs:{i:7,f:2,o:10.5,s:2,n:9}};
    var e = document.createElement('script');
    e.setAttribute('type', 'text/javascript');
    e.setAttribute('src', 'http://browser-update.org/update.js');
    document.body.appendChild(e);
  _shown = true;
}
});

and if the page is reloading between navigation store it in a cookie or as a session variable.

Upvotes: 1

Related Questions