Webview:eval(expr) method


Execute JavaScript code in the current top level document rendered in the WebView.

Parameters

expr

A string representing a valid Javascript expression to be evaluated.

Return value

This function returns a Task instance.
Once finished, the Task will return the result of the Javascript execution as a string, encoded using JSON.

Example

local ui = require "ui" require "webview" -- create a simple Webview local win = ui.Window("Webview:eval() sample", 640, 480) local Webview = ui.Webview(win, "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/PI", 0, 50, 640, 500) local button = ui.Button(win, "Evaluate Javascript Math.PI") button:center() button.y = 10 function button:onClick() Webview:eval("Math.PI").after = function(value) ui.info(value, "Math.PI value from Javascript") end end -- update user interface ui.run(win):wait()