2020.2

Table Of Contents
To latch on to these events, you have to register a olcotgsavestate listener and a
olcotgrestorestate listener, respectively, on the window object. The window object represents a
window containing a DOM (document object model), in this case the COTG Form.
The function callback on its addEventListener method allows you to implement custom code as
part of the save and restore processes.
(For more information about the addEventListener method see the documentation: Mozilla and
w3schools.)
The following code registers the olcotgsavestate listener on the window object.
window.addEventListener('olcotgsavestate', function(event) {
/* code to save custom data */
});
The following snippet does the same for the restore process.
window.addEventListener('olcotgrestorestate', function(event) {
/* code to retrieve custom data and restore custom widgets */
});
The following code combines the previously saved string with the restored URL of a (static)
COTG Camera element:
window.addEventListener("olcotgrestorestate", function(event) {
var value = event.detail.state["myString"];
value = value + $("#camera1 img").attr("src");
$("form p").html(value);
};
Note
You should not register for these events after the document has loaded (e.g. on the
$(document).ready() event), because these events might get triggered before the
document is ready.
Place your code in a separate JavaScript file and make sure to include that file in the Web
context or in the Web section that contains the COTG Form (see "Including a JavaScript file in a
Web context" on page548). For this file, the order in which JavaScript files are included in the
template doesn't matter.
Page 594