I. Description
This document provides a method which uese JS to control the longest preview time of a report and automatically exit if time is out, so as to prevent the system from shutting down because the user previews the report for too long.
II. Method
Use the setTimeout() method provided by JavaScript to perform an operation after a specified period of time. The operation uses window.location to redirect to the login page from the report preview page. However, after jump to the login page, the user's old login session is not over, so we need to use Ajax to interact with the data.
III. Implementation Process
1) Create a new logout.js file in folder %FR_HOME%\webapps\webroot\help, enter the following code, and save
setTimeout(function(){
jQuery.ajax({
URL: "/webroot/decision/logout/cross/domain", // the server provides single sign-on service
data:{},
Timeout: 5000,
Success: function (data) {
window.location = "/webroot/decision/login";
},
Error: function() {
alert("error"); //If fails to login (timeout or other server errors)
}
});
}, 3600); //Maximum preview time (unit: millisecond)
For testing purposes, it is set to exit the report after 3600 milliseconds, i.e. 3.6 seconds, which can be modified according to actual needs.
2) Open Template > Web Attributes > Reference JavaScript, select the file logout.js, click Add, and then the report can reference the JS file:
3) Preview. You will find that after 3.6 seconds, the report will automatically exit and enter the system re-login interface, as shown below:
So far, our method of controlling the template preview life cycle through JavaScript has been successfully implemented.
Note: If you want all reports in the server follow this setting, you need to reference logout.js in Server > Server Configuration Managemer > Reference Javascript.