Friday, March 1, 2013

Detect the browsers in which MS CRM is opened using JavaScript


After the introduction of cross-browser support for Dynamics CRM 2011, developer now need to make their custom JavaScript compatible with all browsers on which the CRM users running their CRM. There are different ways to detect a user’s browser with JavaScript.

Here is one such approach which MS used to find the browser in MS CRM. MS uses Mscrm.Utilities function to detect the browser in which user is running CRM. Using this we can identify different browsers like FireFox, Chrome, IE9 or 10.
 

Mscrm.Utilities.isFirefox = function () {
   
 return Sys.Browser.agent === Sys.Browser.Firefox
};
Mscrm.Utilities.isIE =
 function () {
   
 return Sys.Browser.agent === Sys.Browser.InternetExplorer
};
Mscrm.Utilities.isChrome =
 function () {
   
 if (navigator.userAgent.toLowerCase().indexOf("chrome") > -1) return true;
   
 else return false
};
Mscrm.Utilities.isIE9 =
 function () {
   
 return Sys.Browser.agent === Sys.Browser.InternetExplorer && Sys.Browser.version === 9
};
Mscrm.Utilities.isIE10 =
 function () {
   
 return Sys.Browser.agent === Sys.Browser.InternetExplorer && Sys.Browser.version === 10
};
Here is the sample function to akert the user about the browser in which a user opens a MS CRM:

function detectBrowser() {
   
 if (Mscrm.Utilities.isIE()) {
        alert("This is IE");
    }
   
 if (Mscrm.Utilities.isFirefox()) {
        alert("This is Firefox");
    }
   
 if (Mscrm.Utilities.isChrome()) {
        alert("This is Chrome");
    }
}
 
 
Hope this helps!!!!

No comments:

Post a Comment