Onload scripting for each window

How do I run scripts when a window loads? Is there an “onload” event?

Right click on the Window in the Project Browser, then click “Event Handlers”. Select one of the following to place your code. I recommend trying out internalFrameActivated first.

internalFrameActivated - fired when the window becomes the focused window
• internalFrameClosed - fired after the window is closed
• internalFrameClosing - fired just before the window is closed
• internalFrameDeactivated - fired when the window loses focus
internalFrameOpened - fired the first time a window is opened after not being in the cache

Very nice, thank you. If this is in the manual, I am sorry I missed it.

No problem - that one wasn’t obvious to find in the manual.

inductiveautomation.com/support/ … _types.htm

Be careful with internalFrameActivated. If you have more than one window opened and change focus from one to the other, the window with the internalFrameActivated event script will fire when it regains focus, causing any script within the event to run (as opposed to only on open).

Using internalFrameOpened can also present a coding issue in that the event will fire the fist time the windows is opened and inserted into the cache. Closing the window does not necessarily remove it from the cache and subsequent opening of the window will not fire the event.

Mark - correct. You can change the cache policy of the window.

The manual page on Window properties covers your caching options.

In Ignition 7.5 there will be windowOpened and windowClosed events that will avoid then confusion of the internal frame events

Will there also be a windowFocus event?

No, that’s exactly how internalFrameActivated behaves

Is there any updated answer in 2022?
I use Ignition 8.1.

Vision window opened:
https://docs.inductiveautomation.com/display/DOC81/Component+Events#ComponentEvents-VisionWindowEventHandlers
Perspective page startup:
https://docs.inductiveautomation.com/display/DOC81/Perspective+Session+Event+Scripts#PerspectiveSessionEventScripts-PageStartup
Perspective view/component startup:
https://docs.inductiveautomation.com/display/DOC81/Perspective+Event+Types+Reference#PerspectiveEventTypesReference-SystemEvents

1 Like