Auto Reload

Jenkinsj5
Jenkinsj5 Member
edited February 11, 2022 in Analytics #1
I have a legacy BIRT (2.6.1) report that is using a text block, set to HTML, causing the report to reload every 60 seconds. I am recreating the report in BIRT 4.2.1<br />
<br />
I did some research and it appears to have been sourced from <a class='bbc_url' href='http://www.eclipse.org/forums/index.php/mv/tree/163879/#page_top'>http://www.eclipse.org/forums/index.php/mv/tree/163879/#page_top</a&gt; (Jason Weathersby) which is probably an updated version of <a class='bbc_url' href='http://www.birt-exchange.org/org/devshare/designing-birt-reports/69-periodically-reload-birt-report/'>http://www.birt-exchange.org/org/devshare/designing-birt-reports/69-periodically-reload-birt-report/</a&gt; (Virgil)<br />
<br />
The Jason?s version is obviously simpler than Virgil?s, but JSLint is less than happy with the Jason?s JavaScript<br />
<br />
I cleaned it up some, JSLint is happier, but not content; and mine remains a rework of a generations old solution.<br />
<br />
Suggestions for a fresh approach, or rework to make JSLint happy would be appreciated. <br />
<br />
<br />
<strong class='bbc'>Legacy Version</strong><br />
<em class='bbc'>With URL ending ?ReportName.rptdesign &__overwrite=true?</em><br />
<form name="input" onSubmit="return reloadPage();"><br />
<br />
<script type="text/javascript"><br />
<br />
function reloadPage() {<br />
var targetURL = new String(location.href);<br />
location.replace(targetURL);<br />
return false;<br />
}<br />
<br />
timer=setTimeout('reloadPage()', 60000);<br />
</script><br />
<br />
<br />
<br />
<strong class='bbc'>My Version</strong><br />
<em class='bbc'>Without URL Parameters</em><br />
<form name="input" onSubmit="return reloadPage();"><br />
<br />
<script type="text/javascript"><br />
<br />
<br />
function reloadPage() {<br />
'use strict';<br />
location.reload(true);<br />
}<br />
<br />
timer = setTimeout(reloadPage, 60000);<br />
</script>
Warning No formatter is installed for the format ipb

Comments

  • kclark
    kclark E Member
    edited December 31, 1969 #2
    I reworked your code a little bit. It's working for me in BIRT 3.7.2 and JSLint didn't give me any errors with it either.<br />
    <br />
    <pre class='_prettyXprint _lang-auto _linenums:0'>
    <html>

    <body>
    <script type="text/javascript">
    /*global setTimeout*/
    /*global location*/
    /*global document*/
    'use strict';

    function reloadPage() {
    location.reload(true);
    }

    var timer;
    timer = setTimeout(reloadPage, 60000);

    document.getElementById("input").onsubmit = function () {
    reloadPage();
    };
    </script>

    <form name="input">
    </form>

    </body>
    </html>
    </pre>
    Warning No formatter is installed for the format ipb
  • Jenkinsj5
    Jenkinsj5 Member
    edited December 31, 1969 #3
    Thanks Clark :)<br />
    <br />
    Works great in 4.2.1 also. I dropped your code as is, into a text block, set to HTML and it reloads the page every 60 seconds (<em class='bbc'>60000 milliseconds</em>).
    Warning No formatter is installed for the format ipb
  • setTimeout() and setInterval() functions allow you to execute a piece of JavaScript code/function at a certain point in the future. setInterval repeats the call, setTimeout only runs it once.

    setTimeout(expression, timeout); runs the code/function once after the timeout. It is a time based code execution method that will execute script only one time when the interval is reached, and not repeat again unless you gear it to loop the script by nesting the setTimeout object inside of the function it calls to run. If geared to loop, it will keep firing at the interval unless you call clearTimeout(). If you want something to happen one time after some seconds Then use setTimeout... because it only executes one time when the interval is reached.

    setTimeout(function() {

     console.log('Wait 3 seconds and I appear just once');

    }, 3000);

    setInterval(expression, timeout); runs the code/function repeatedly, with the length of the timeout between each repeat. It is a time interval based code execution method that has the native ability to repeatedly run specified script when the interval is reached. It should not be nested into its callback function by the script author to make it loop, since it loops by default. It will keep firing at the interval unless you call clearInterval(). If you want to loop code for animations or clocks Then use setInterval.

    setInterval(function() {

     console.log('Every 3 seconds I appear on your console');

    }, 3000)