Logic Machine Forum
equivalent to "window.onload" - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Visualization (https://forum.logicmachine.net/forumdisplay.php?fid=9)
+--- Thread: equivalent to "window.onload" (/showthread.php?tid=1427)



equivalent to "window.onload" - SigmaTec - 06.06.2018

Hi all,


I'm looking for this method :
how to detect that a page (whatever this page, not a particular page) has just been loaded, with an equivalent of "window.onload" in javascript?

Someone knows the solution (Erwin for example ;-))?

Have a good day !


RE: equivalent to "window.onload" - admin - 06.06.2018

Can you explain what are you trying to achieve?


RE: equivalent to "window.onload" - SigmaTec - 06.06.2018

Hi ,

here is my need:
with custom JS, change the value of a group [JS grp.write()] each time a page of the visualization is accessed by a user.
Note: that's why I was referring to the JS instruction "window.onload".

It is necessary for this:
1. I detect the Id of the activated page
2. I write in a value in a group

Hoping you have been more accurate ...


RE: equivalent to "window.onload" - Erwin van der Zwart - 06.06.2018

Hi,

You can do that like this:
Code:
$(function(){
  $('body').on('showplan', function(e, id) {
     grp.write('1/1/1', id);
  });
});
BR,

Erwin


RE: equivalent to "window.onload" - DGrandes - 24.06.2021

Hi,

I want to write an object before I close visualization window.

I think the function is "window.onbeforeunload" but witch is the equivalent?

Is there any page to see all javascript function in Logic Machine?

Thanks!!


RE: equivalent to "window.onload" - admin - 25.06.2021

The visualization runs in a browser not in LM. The supported functions is what the browser supports.

This can be used to switch an object off when the visualization page is exited:
Code:
window.onbeforeunload = function() {
  if ($('body').hasClass('usermode')) {
    grp.write('32/2/21', false);
  }
};



RE: equivalent to "window.onload" - DGrandes - 30.06.2021

(25.06.2021, 11:48)admin Wrote: The visualization runs in a browser not in LM. The supported functions is what the browser supports.

This can be used to switch an object off when the visualization page is exited:
Code:
window.onbeforeunload = function() {
  if ($('body').hasClass('usermode')) {
    grp.write('32/2/21', false);
  }
};


Thanks!! It worsk perfectly.

I have another question, I want to know when a visualization is opened and I put this code:

Code:
  grp.write('32/1/152', true);
 
  window.onbeforeunload = function() {
    if ($('body').hasClass('usermode')) {
      grp.write('32/1/152', false);
    }
  };

But doesn´t work.

What is wrong?

Thanks!


RE: equivalent to "window.onload" - admin - 30.06.2021

You have to wait for the WebSocket connection to be established. Use this:
Code:
if (typeof localbus === 'object') {
  $(localbus).on('connect', function() {
    grp.write('32/1/152', true);
  });
}