1

I have a requirement in my project to show outdated browser message when user uses old browser.

I am using angular 1.5.5. I tried with angular-bowser module which works on angular supported browser, but the problem comes with old versions like IE8, which doesn't support my angular version . So angular-bowser module doesn't work .

Can somebody let me know about any other ways or some library or anything in that matter that can help?

4
  • Have you tried using native javascript to check browser version ? Commented Aug 5, 2016 at 13:13
  • modernizr may help, although I don't know of any specific implementation to help with Angular compatibility. Generally speaking, the better practice is to do feature detection with a browser. Commented Aug 5, 2016 at 13:19
  • try this $window.navigator.userAgent Commented Aug 5, 2016 at 13:21
  • Possible duplicate of Browser detection in JavaScript? Commented Aug 5, 2016 at 13:46

4 Answers 4

4

because angularjs doesn't just depend on angular modules you can use native javascript like so to detect the browser version:

JAVASCRIPT:

navigator.sayswho= (function(){
    var ua= navigator.userAgent, tem, 
    M= ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
    if(/trident/i.test(M[1])){
        tem=  /\brv[ :]+(\d+)/g.exec(ua) || [];
        return 'IE '+(tem[1] || '');
    }
    if(M[1]=== 'Chrome'){
        tem= ua.match(/\b(OPR|Edge)\/(\d+)/);
        if(tem!= null) return tem.slice(1).join(' ').replace('OPR', 'Opera');
    }
    M= M[2]? [M[1], M[2]]: [navigator.appName, navigator.appVersion, '-?'];
    if((tem= ua.match(/version\/(\d+)/i))!= null) M.splice(1, 1, tem[1]);
    return M.join(' ');
})();

//Invoke 
navigator.sayswho;

You can use this function to determine current browser and version in your angular app and do your message dialog accordingly. Something like

JAVASCRIPT

var version = navigator.sayswho;

if (version <= 8) {
    alert("Browser outdated! Please update browser!");
    return false; //don't forget.
}
Sign up to request clarification or add additional context in comments.

Comments

1
let isMobile = /Android|iPhone/i.test(window.navigator.userAgent)

Comments

0

I suggest looking at Bowser; it's sole purpose is browser detection. Check out the details here

Comments

0

You can use this

$scope.isOpera = !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
// Opera 8.0+ (UA detection to detect Blink/v8-powered Opera)
$scope.isFirefox = typeof InstallTrigger !== 'undefined'; // Firefox 1.0+
$scope.isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
// At least Safari 3+: "[object HTMLElementConstructor]"
$scope.isChrome = !!window.chrome && !$scope.isOpera; // Chrome 1+
$scope.isIE = /*@cc_on!@*/ false || !!document.documentMode; // At least IE6


function getDevice() {
  var userAgent = navigator.userAgent || navigator.vendor || window.opera;
  if (userAgent.match(/iPhone/i) || userAgent.match(/Android/i)) {
     // you can write code here for mobile
  }
}

function hasGetUserMedia() {
  return !!(navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia);
}

if (!hasGetUserMedia()) {
  alert('Your browser is not supported. Please switch to Google Chrome or Mozilla Firefox.');
}

Only the value of current browser will be true

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.