I. Description
When developing reports, we may need to collect information about the URL of the currently opened report page. Although FineReport currently has some built-in system parameters that can meet certain needs, it is not perfect. For example, there is no system parameters that can get the title of a webpage.
II. Example
Open the file %FR_HOME%\webapps\webroot\WEB-INF\reportlets\GettingStarted.cpt and add a Click event for the "Query" button, as shown in the following figure:
JavaScript code:
var test1 = window.location.href;
alert('URL: '+test1);
//window.location.protocol(get the protocal of URL)
var test2 = window.location.protocol;
alert('URL Protocol: '+test2);
//window.location.host(Get the host part of the URL)
var test3 = window.location.host;
alert('URL Host: '+test3);
//window.location.port(Get the port number with URL)
var test4 = window.location.port;
alert('URL Port: '+test4);
//window.location.pathname(Get the path part of the URL)
var test5 = window.location.pathname;
alert('URL Path Name: '+test5);
//window.location.search(Get the part of the URL attribute following the question mark)
var test6 = window.location.search;
alert('URL Search: '+test6);
//Get the page title corresponding to the URL
var test7 = document.title;
alert('URL Title: '+test7);
After saving, the effect is as follows: