JS to get the current browser type

Source: Internet
Author: User

This article for Bo Master Original, reproduced please indicate the source:

When the POI is applied for export, the POI is applied to encapsulate the data, the data is encapsulated in Excel, and then the download download operation is done to complete

POI export operation. As the download operation, the browser will be differentiated and adapted to be exported separately. Due to less adaptation, resulting in IE browser

Export has failed to export.

Finally found that in JS does not recognize the adaptation of IE, the method is applied as follows:

function Getbrowserinfo () {    = {};     = navigator.userAgent.toLowerCase ();     =/(Msie|firefox|chrome|opera|version). *? ([\d.] +)/;     = Ua.match (re);     Try {        = M[1].replace (/version/, "' Safari");         = M[2];    } Catch (e)    {        Console.log ("getbrowserinfo fail.") )    }    return  Sys;}

The above method will be identified in JS and return the corresponding browser type.

Here's how to modify it later:

functionMybrowser () {varuseragent = navigator.useragent;//get the useragent string for the browser    varIsopera = Useragent.indexof ("Opera") >-1;//determine if Opera browser    varIsie = Useragent.indexof ("compatible") >-1 && useragent.indexof ("MSIE") > 1 &&!isopera ;//determine if IE browser    varIsedge = Useragent.indexof ("Edge") >-1;//determine if IE's Edge browser    varIsFF = Useragent.indexof ("Firefox") >-1;//determine if Firefox browser    varIssafari = Useragent.indexof ("Safari") >-1 && useragent.indexof ("Chrome") = = 1;//determine if Safari browser    varIschrome = Useragent.indexof ("Chrome") >-1 && useragent.indexof ("Safari") >-1;//determine the Chrome browser    if(Isie) {varReie =NewRegExp ("MSIE (\\d+\\.\\d+);");        Reie.test (useragent); varFieversion = parsefloat (regexp["$"]); if(Fieversion = = 7) {            return"IE7"; } Else if(Fieversion = = 8) {            return"IE8"; } Else if(Fieversion = = 9) {            return"IE9"; } Else if(Fieversion = = 10) {            return"IE10"; } Else if(Fieversion = = 11) {            return"IE11"; } Else {            return"0"; }//IE version is too low        return"IE"; }    if(Isopera) {return"Opera"; }    if(Isedge) {return"Edge"; }    if(IsFF) {return"FF"; }    if(Issafari) {return"Safari"; }    if(ischrome) {return"Chrome"; }    }

After the browser in the background to adapt, then you can export the success.

JS to get the current browser type

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.