59
Views
6
Comments
Javascript, refresh container on window.onfocus
Question
Hi all,

I'm trying to implement a function in javascript that runs when i set focus on window. For now i have on the preparation of my screen (in a RunJavascript action) this code;

"window.onfocus = function() {window.close()};"

It is working, every time a set the focus on that window it appears a confirmation message to close the window. But, what i'm trying to do is;
By the ID of one container, refresh his content. Is that possible ? Is this the right way to do it ?
2023-01-29 21-43-42
António Rodrigues
Hello!

Based on this post i'm trying to call an action when function window.onfocus take place was. I have attached an example, but i getting an error in document.getElementById". Can anyone check this, and help me on this?
CallAction.oml
2022-01-06 13-41-20
Ricardo Araújo
HI António,

instead of having document.getElementById(Hiddenbutton.Id). click();

try document.getElementById("'" + Hiddenbutton.Id + "'").click();

RNA
2023-01-29 21-43-42
António Rodrigues
Hello Ricardo. Thanks for your reply.


I have now, something like this.

window.onfocus = function xpto()
{
document.getElementById("'" + Hiddenbutton.Id + "'").click();
}

But it keeps with an error..

Mensagem: 'Hiddenbutton' não está definido
Linha: 3
Caráct: 1
Código: 0
URL: https://localhost/CallAction/admin/CallFunction.js?239

2022-01-06 13-41-20
Ricardo Araújo
António,

instead of using style property display "display: none;" , use Visible = False property instead (that is how you should make invisible the objects)

If the goal is to see a feedback message in screen then, you have to have a reference to webblock RichWidgets\Feedback_Message and have one in your page

You could use the RichWidgets\Listlateload webblock to trigger the screen action you need, instead of writing javascript.

RNA
2023-01-29 21-43-42
António Rodrigues
Ricardo,

Thanks for the tip, but the main goal of this example, is trying to understand, and learn how to call an action using javascript. By using event window.onfocus.
2022-01-06 13-41-20
Ricardo Araújo
Hi Antonio,

in that case use document.getElementById('wtHiddenbutton').click();

You can see the generated code that the there is a prefix Wt in button.

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