Using the FR Object

  • Last update:August 07, 2026
  • Overview

    When you preview a report on the frontend, FineReport converts the template into HTML and references finereport.js, the built-in FineReport JavaScript file, in the HTML head tag. The code is as follows:

    <script type="text/javascript" src="/webroot/decision/view/report?op=emb&resource=finereport.js"></script>

    finereport.js is not a physical file in the report project directory. Instead, FineReport assembles it on the server from multiple JavaScript files. finereport.js provides many built-in functions and public properties. After a template or another web page references finereport.js, you can use the FR object to call public properties and methods in the FR.xxx format. For details about the properties and methods of the FR object, see Global API.

    Function Description

    When a report is loaded, finereport.js is automatically referenced. Therefore, you can directly use FR.xxx to call FR methods in JavaScript code added to the report. To call FR methods on your own web page, first reference finereport.js in the HTML head tag, and then call the methods in the FR.xxx format.

    Example

    Calling FR Methods in a Report

    Adding a Button

    Create a general report, select cell A1, add a button widget to the cell, and set Button Name to Test, as shown in the following figure.

    Adding an Event

    Select cell A1, choose Widget Setting > Event on the right property panel, and add a Click event to the button, as shown in the following figure.

    The JavaScript code is as follows:

    FR.showDialog("Test",600,400,"Hello World")
    Previewing the Effect

    Save the report and select Data Entry Preview. After you click the Test button, a prompt box is displayed, as shown in the following figure.

    Calling FR Methods on a Web Page

    Creating an HTML File

    Create an HTML file to implement the effect: when you click a custom button, a prompt box pops up. Because the button calls the showDialog method of the FR object, you need to reference finereport.js in the code. The code is as follows:

    Click to download the HTML file: Test.html.zip

    iconNote: 
    The code also references the CSS style for the pop-up box.
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

    <html>
     <head>
      <title>FineReport Demo</title>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
      <script type="text/javascript" src="/webroot/decision/view/report?op=emb&resource=finereport.js"></script>
      <link rel="stylesheet" type="text/css" href="/webroot/decision/view/report?op=emb&amp;resource=finereport.css&amp;cssVersion=1557882553214">
      <script>
    function button_onclick(){
    FR.showDialog("Test", 600, 400, "Hello World")
    }
    </script>
    <input type="button" value="Test" onclick="javascript:button_onclick();" />
     </head>
     <body>
    </body> 
    </html>

    Adding the HTML File to the Project

    Save the HTML file to FineReport installation directory/webapps/webroot, as shown in the following figure.

    Previewing the Effect

    iconNote: 
    The project must be running during preview.

    Open a browser and enter the URL of the HTML file in the address bar. For example, for a local project, enter http://localhost:8075/webroot/Test.html to access the file.

    After you click the Test button, a prompt box is displayed. The effect is the same as in the "Calling FR Methods in a Report" section, as shown in the following figure.

    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