You can use $Browser global value provider to return information about the hardware and operating system of the browser accessing the application as described in the link below:
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/expr_browser_value_provider.htm
But it cannot be used to detect the browser type or version number.
You can use the below code to detect the browser on which you are running your Lightning application. Here, I am checking whether I am on Internet Explorer or not:
checkBrowser: function (component) {
var browserType = 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(' ');
})();
if (browserType.startsWith("IE")) {
component.set("v.isIE", true);
}
}
If the value of isIE attribute is true, then you are running on Internet Explorer. Similarly you can check for Chrome, Firefox, Opera and other browsers.
awesome cool. Keep up the good work.
ReplyDelete