Legato
Legato

GoFiler Legato Script Reference

 

Legato v 1.6e

Application v 6.3a

  

 

Chapter Twenty-oneWebView Interface (continued)

JavaScriptAddTopLevel Function

Overview

The JavaScriptAddTopLevel function adds a JavaScript code segment that is executed on every page load.

Syntax/Parameters

Syntax

int = JavaScriptAddTopLevel ( handle hWVO, string code | wstring code );

Parameters

hWVO

A handle specifying a WebView Object.

code

A string or wstring specifying JavaScript code to execute.

Return Value

An int as ERROR_NONE (0) or a formatted error code on failure.

Remarks

The top level script is executed while the page is still navigating. Developers can use the top level script to determine when the page has finished loading. For example, the following JavaScript will post a “page loaded” message to Legato when the current page is finished loading.

function pageReadyHandler() {
    window.chrome.webview.postMessage('page loaded');
}

if (document.readyState === 'complete' || document.readyState === 'interactive') {
    setTimeout(pageReadyHandler, 1);
} else {
    document.addEventListener('DOMContentLoaded', pageReadyHandler);
}

The data in this script is temporary as each loaded page will get a new copy of the script. To persist data between page loads use the JavaScriptSetMessageHandler function to send messages back to Legato and the JavaScriptRun function to add more data to the active page.

Related Functions

Platform Support

Go13, Go16, GoFiler Complete, GoFiler Corporate, GoFiler, GoFiler Lite, GoXBRL

Page revised 2025-10-20