Webview:addinitscript(script) method


Add the provided JavaScript to a list of scripts that should be executed before the HTML document has been loaded and before any other script included by the HTML document is executed.

To take effect, this function must be called once the Webview widget is initialized, before loading any document. It means that the provided scripts won't be executed if you provide an URL when calling the Webview widget constructor.

Parameters

expr

A string representing a valid Javascript expression to be evaluated.

Return value

This function returns no value.

Example

local ui = require "ui" require "webview" -- create a simple Webview local win = ui.Window("Webview:addinitscript() sample", 640, 480) local Webview = ui.Webview(win, "") Webview.align = "all" function Webview:onReady() Webview:addinitscript("alert('Hello world !')") Webview.url = "https://google.com" end win:show() -- update the user interface until the user closes the Window repeat ui.update() until not win.visible