JS Judge Browser Language

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

    FineReport is a multilingual and cross-platform report designer. Customers often need to use multiple language environments to configure reports.

    How to automatically jump to the page of the corresponding language by judging the browser language environment?

    1606359743609265.gif

    II. Example

    Create a new template, add a button to cell A1and add a Click event for this button.

    1606359743767749.png

    The code for the event:

    var type = navigator.appName
    if (type == "Netscape") {
    var lang = navigator.language
    } else {
    var lang = navigator.userLanguage
    }
    //Get the first two letters of the browser language
    var lang = lang.substr(0, 2)
    // Judge English
    if (lang == "en") {
    window.location.href = "https://www.finereport.com/en/"
    //  Jump to English url
    }
    // Judge Japanese
    else if (lang == "ja") {
    window.location.href = "http://www.finereport.com/jp/"
    //  Jump to Japanese url
    }
    // In addition to the languages listed above
    else {
    window.location.href = "http://www.finereport.com/"
    //  Jump to urls in other languages
    }

    The page will automatically recognize the default browser language and jump to the corresponding URL for the language as defined in the code above.

    Save the template, and click Pagination Preview to see the effect.

    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