41
Views
3
Comments
Ajax refresh timer of widgets
Question

Is there a way to periodically refresh a widget (webblocks)

if so, how?


2019-09-17 09-11-00
João Pedro Abreu
Staff
I'm not sure if this is what you're after, but there's a setInterval javascript function that can be used to that effect.

In the following example RefreshBt.Id is the ID of a button that triggers an action with an AJAX refresh for the desired element. Site.RefreshPooling is the refresh interval, in seconds.

<script type='text/javascript'>
 
function UpdateMessages(id)
{
  document.getElementById('" + RefreshBt.Id + "').click();
  return false;
}
 
setInterval('UpdateMessages()', " + Site.Refresh_Pooling*1000 + ");
</script>
<script type='text/javascript'>
function UpdateMessages(id)
{
  document.getElementById('" + RefreshBt.Id + "').click();
  return false;
}
 
setInterval('UpdateMessages()', " + Site.Refresh_Pooling*1000 + ");
</script>
"<script type='text/javascript'>
 
function UpdateMessages(id)
{
  document.getElementById('" + RefreshBt.Id + "').click();
  return false;
}
 
setInterval('UpdateMessages()', " + Site.Refresh_Pooling*1000 + ");
</script>"
"<script type='text/javascript'>
 
function UpdateMessages(id)
{
  document.getElementById('" + RefreshBt.Id + "').click();
  return false;
}
 
setInterval('UpdateMessages()', " + Site.Refresh_Pooling*1000 + ");
</script>"
UserImage.jpg
Dror Svartzman
João,

How can i implment javascript in the code? Under Screen's Extended properties\Web screen Javascript?

Dror



2017-10-02 14-22-21
Paulo Tavares
Staff
Hi Dror.

What are you trying to do, specifically?

What João said is the way to do it. He uses the code

<script type='text/javascript'>
function UpdateMessages(id)
{
  document.getElementById('" + RefreshBt.Id + "').click();
  return false;
}
 
setInterval('UpdateMessages()', " + Site.Refresh_Pooling*1000 + ");
</script>

probably in an unescaped expression (an Expression widget with the Escaped property set to false), from the syntax, where:

- UpdateMessages is the function to be called after each interval;
- Site.Refresh_Pooling is a site property where you set the interval (in seconds) after which the javascript function should be executed;
- RefreshBt.Id is, in this case, the widget's ID, since in his case he wants to click a button every X seconds.

Does this make it clearer for you?

Regards,

Paulo Tavares
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.