Skip to content

Instantly share code, notes, and snippets.

@ikonikre
Created September 23, 2016 16:00
Show Gist options
  • Save ikonikre/a58a6f831d6f249f87781c5d742ab5bf to your computer and use it in GitHub Desktop.
Save ikonikre/a58a6f831d6f249f87781c5d742ab5bf to your computer and use it in GitHub Desktop.
Detect browser script.
<script>
var message = '';
var ba = [ "Chrome", "Firefox", "Safari", "Opera", "MSIE", "Trident", "Edge" ];
var b, ua = navigator.userAgent ;
for ( var i=0; i < ba.length; i++ ) {
if ( ua.indexOf(ba[i]) > -1 ) {
b = ba[i] ;
break ;
}
}
if ( b == 'MSIE' || b == 'Trident' ) {
b = 'Internet Explorer' ;
message = '<style>.bl{color:blue;text-decoration:underline;}</style><div class="container m-y-3 alert alert-info alert-dismissible fade in" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><strong>' + b + '</strong> is not supported by this Web site due to its age and security flaws.<br /><span class="small">Switch to a modern browser, like <a class="bl" href="http://firefox.com">Firefox</a> or <a class="bl" href="http://google.com/chrome/">Chrome</a>, and try again. Otherwise this site may not function correctly and your personal information may be unnecessarily exposed to third-parties.</span></div>' ;
document.getElementById('browserAlert').innerHTML = message ;
}
</script>
<span id="browserAlert"></span>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment