The project is occasionally used to determine the browser type and related version of the problem, now record the relevant code:
functionGetbrowserinfo (useragent) {varBrowsername, browserversion; if(Useragent.indexof ("MSIE") > 1) { varTypes = useragent.substring (Useragent.indexof ("MSIE")); varInfo = (Types.split (";") [0]). Split (""); Browsername= Info[0]; Browserversion= Info[1]; } Else if(Useragent.indexof ("Firefox") >-1) { varTypes = useragent.substring (Useragent.indexof ("Firefox"))); varInfo = (Types.split ("") [0]). Split ("/"); Browsername= Info[0]; Browserversion= Info[1]; } Else if(Useragent.indexof ("Chrome") >-1) { varTypes = useragent.substring (Useragent.indexof ("Chrome")); varInfo = (Types.split ("") [0]). Split ("/"); Browsername= Info[0]; Browserversion= Info[1]; } Else if(Useragent.indexof ("Opera") >-1) { varTypes = useragent.substring (Useragent.indexof ("Opera")); varInfo = (Types.split ("") [0]). Split ("/"); Browsername= Info[0]; Browserversion= Info[1]; } Else if(Useragent.indexof ("Safari") >-1) { varTypes = useragent.substring (Useragent.indexof ("Safari")); varInfo = (Types.split ("") [0]). Split ("/"); Browsername= Info[0]; Browserversion= Info[1]; } Else if(Useragent.indexof ("rv") >-1) {//For IE11 varsubstring = useragent.substring (useragent.indexof ("rv"), Useragent.indexof (")")); Browsername= "MSIE"; Browserversion= Substring.split (":") [1]; } if(Browserversion.indexof ('. ')! =-1) {browserversion= browserversion.substring (0, Browserversion.indexof ('. '))); } returnBrowsername + "-" +browserversion; }
Test:
Getbrowserinfo (navigator.useragent);
JavaScript Browser type and version number