1.6.3Widget lifecycle

Widget lifecycle is a little more complicated because a widget is a web page and there are two separate events: loading of the HTML page, and loading of the framework.

Widgets should (normally) have an OnLoad() function. This is called by the framework when it has finished loading, and your code should not try to use any part of the framework - retrieving data, carrying out actions such as placing trades - before the framework says it is ready by calling your OnLoad().

For example, the following code is not safe and won't work:

// Create an instance of the framework

var Framework = new FXB.Framework();

// OnLoad handler

Framework.OnLoad = function() { … Called asynchronously. Framework is now ready };

// **WON'T WORK**. This is executed immediately, before the framework has

// had a chance to set itself up, and before it has done a callback into OnLoad().

Framework.Ask(…);

If the user has added your widget into the MyTrader page container, then the widget runs until the user switches to another page. You can't "close" your widget in this context (which would leave a blank space in the page).

If the user has loaded your widget as a dialog or floating panel, then you can choose to close the window. The framework's CancelDialog() function will close the window (and will have no effect if your widget has been added into the page container).