JS Check Browser Type

  • Last update:  2020-12-17
  • I. Description

    Sometimes IE browsers cannot display some pages, so we need to define different pages for different browser types. How to distinguish the browsers?

    We can make the judgement by the user-agent header of the browser, and then use the pop-up box to display the browser type, the effect is as follows:

    1606357813109927.gif

    II. Example

    Create a new template, insert a button in cellA1, name it check browser, and add a Click event:

    1606357813434047.png

    function myBrowser(){
        var userAgent = navigator.userAgent; //Get the userAgent string of the browser
        var isOpera = userAgent.indexOf("Opera") > -1;
        if (isOpera) {
            return "Opera"
        }; //Determine whether it is Opera browser
        if (userAgent.indexOf("Firefox") > -1) {
            return "FF";
        } //Determine whether it is the Firefox browser
        if (userAgent.indexOf("Chrome") > -1){
      return "Chrome";
     }
        if (userAgent.indexOf("Safari") > -1) {
            return "Safari";
        } //Determine whether it is Safari browser
        if (userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera) {
            return "IE";
        }; //Determine whether it is IE browser
    }
    //The following is to call the above function
    var mb = myBrowser();
    if ("IE" == mb) {
        alert("I am IE");
    }
    if ("FF" == mb) {
        alert("I am Firefox");
    }
    if ("Chrome" == mb) {
        alert("I am Chrome");
    }
    if ("Opera" == mb) {
        alert("I am Opera");
    }
    if ("Safari" == mb) {
        alert("I am Safari");
    }

    Save the template, click Data Entry Preview, and the effect is as shown in the beginning.

    III. Completed template

    Attachment List


    Theme: Secondary Development
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy