0

I have a problem.I need to detect the browser Microsoft edge using Javascript.I am explaining my code below.

<input type="button" class="btn btn-success"   id="saveData" value="Browser"   style="margin-right:20px;" onclick="CheckBrowser();" />


function CheckBrowser() {
  var x = checkBrowserType();
  alert("your browser is "+ x);
}

    function checkBrowserType() {
      var objappVersion = navigator.appVersion;
      var objAgent = navigator.userAgent;
      var objbrowserName = navigator.appName;
      var objfullVersion = '' + parseFloat(navigator.appVersion);
      var objBrMajorVersion = parseInt(navigator.appVersion, 10);
      var objOffsetName, objOffsetVersion, ix;
      if ((objOffsetVersion = objAgent.indexOf("Chrome")) != -1) {
        objbrowserName = "Chrome";
      } else if ((objOffsetVersion = objAgent.indexOf("MSIE")) != -1) {
        objbrowserName = "Microsoft Internet Explorer";
      } else if ((objOffsetVersion = objAgent.indexOf("Firefox")) != -1) {
        objbrowserName = "Firefox";
      } else if ((objOffsetVersion = objAgent.indexOf("Safari")) != -1) {
        objbrowserName = "Safari";
      } else if ((objOffsetName = objAgent.lastIndexOf(' ') + 1) < (objOffsetVersion = objAgent.lastIndexOf('/'))) {
        objbrowserName = objAgent.substring(objOffsetName, objOffsetVersion);
        objbrowserName = objAgent.substring(objOffsetName, objOffsetVersion);
      } else {}
      return objbrowserName;
    }

Here i have a button and when user will click on that button the respective browser should detect.Here I also need to detect the browser Microsoft edge.Please help me.

  • 1
    You'd be much better off checking for the actual feature that you want to use. Detecting browsers themselves is generally a flawed approach that is prone to breaking and has to be continuously updated with the times. – Wesley Smith Aug 26 '16 at 05:42
  • 1
    Here is the answer - http://stackoverflow.com/questions/33152523/how-do-i-detect-ie-and-edge-browser – David R Aug 26 '16 at 05:44
  • Why do you want to browser detect? Check out [this answer](http://stackoverflow.com/a/1294859/794234) and [this answer](http://stackoverflow.com/a/1294765/794234) which discuss the problems with browser detection. – just.another.programmer Aug 26 '16 at 05:44
  • Actually i have some features in my application whose api is depends on different browser so i need this. –  Aug 26 '16 at 05:54
  • @DavidR : i followed that link but its detecting `chrome` in edge browser.actually navigator object is giving the out put like this `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586` in browser console. –  Aug 26 '16 at 06:23

0 Answers0