How to intelligently obtain UA information on browser version
How to get UA (user Agent) user agent with js
<!DOCtype html><html><head><title></title></head><body onload="whatBrowser()"><script>function whatBrowser() { document.Browser.Name.value=navigator.appName; document.Browser.Version.value=navigator.appVersion; document.Browser.Code.value=navigator.appCodeName; document.Browser.Agent.value=navigator.userAgent; } </script><table><form name="Browser"><tr><td> Browser name: </td><td> <input type="txt" name="Name" size="110%"></td></tr><td> Version number: </td><td> <input type="txt" name="Version" size="110%"></td></tr><tr><td> Code name: </td><td> <input type="txt" name="Code" size="110%"></td></tr><td> User agent ID: </td><td> <input type="txt" name="Agent" size="110%"></td></tr></form></table></body></html>Functional code
/** Intelligently obtain browser version information**/var browser={ versions:function(){ var u = navigator.userAgent, app = navigator.appVersion; return {//Mobile terminal browser version information trident: u.indexOf('Trident') > -1, //IE kernel presto: u.indexOf('Presto') > -1, //opera kernel webKit: u.indexOf('AppleWebKit') > -1, //Apple and Google kernel gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //Firefox kernel mobile: !!u.match(/AppleWebKit.*Mobile.*/)||!!u.match(/AppleWebKit/), //Is it a mobile terminal ios: !!u.match(//(i[^;]+;( U;)? CPU.+Mac OS X/), //ios terminal android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //Is it an iPhone or QQHD browser iPad: u.indexOf('iPad') > -1, //Is iPad webApp: u.indexOf('Safari') == -1 //Is the web supposed to program, no header and bottom}; }(), language:(navigator.browserLanguage || navigator.language).toLowerCase()}Codes that support mobile judgment
<script> var browser = { versions: function () { var u = navigator.userAgent, app = navigator.appVersion; return { //Mobile terminal browser version information trident: u.indexOf('Trident') > -1, //IE kernel presto: u.indexOf('Presto') > -1, //opera kernel webKit: u.indexOf('AppleWebKit') > -1, //Apple and Google kernel gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //Firefox kernel mobile: !!u.match(/AppleWebKit.*Mobile.*/), //Is it a mobile terminal ios: !!u.match(//(i[^;]+;( U;)? CPU.+Mac OS X/), //ios terminal android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //Android terminal or uc browser iPhone: u.indexOf('iPhone') > -1, //Is it an iPhone or QQHD browser iPad: u.indexOf('iPad') > -1, //Is it an iPad webApp: u.indexOf('Safari') == -1 //Whether the web should be a program, without a header or bottom}; }(), language: (navigator.browserLanguage || navigator.language).toLowerCase() } if (browser.versions.mobile) {//Discerate whether the mobile device is open. The browser code is below var ua = navigator.userAgent.toLowerCase();//Get the object for judgment var u = navigator.userAgent; var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //Android terminal var isiOS = !!u.match(//(i[^;]+;( U;)? CPU.+Mac OS X/); //ios terminal if (ua.match(/MicroMessenger/i) == "micromessenger") { //Open in WeChat} if (ua.match(/WeiBo/i) == "weibo" && isiOS) { //alert("I was opened on Weibo"); var flag; document.addEventListener('touchmove', function (event) { // Listen to scrolling events if(flag==1){ //Execute when the mask is displayed, and scrolling event.preventDefault() is prohibited; //The most critical sentence, prohibiting the default behavior of the browser} }) $(".download-button,#headermenudownlink,#appshareheaderdownlink,#appsharesayhidownlink,#appsharevslogodownlink,#appsharevsdownlink").bind("click",function () { flag = 1; //alert('ios download'); $("#shade-father").css({"display":"block","background-color":"rgba(0,0,0,0.4)"}); //$("body").css("paddingTop","2.3rem"); $("#shade-child").css("height","4rem"); }); $('#shade-father').click(function (){ flag = 0; $("#shade-father").css({"display":"none","background-color":"rgba(0,0,0,0)"}); $("#shade-child").css("height","0"); //$("body").css("paddingTop","0"); }); } if (ua.match(/WeiBo/i) == "weibo" && isAndroid) { } if (ua.match(/QQ/i) == "qq") { //Open in QQ space} if (browser.versions.ios) { //Open in IOS browser} if(browser.versions.android){ //Open in Android browser} } else { //Otherwise it is the PC browser}</script>The above method of obtaining UA information on the browser version of js is all the content shared by the editor. I hope it can give you a reference and I hope you can support Wulin.com more.