revBrowserAddJavaScriptHandler

Typecommand
DictionaryLCS
LibraryLiveCode Script
Syntax
revBrowserAddJavaScriptHandler <instanceID>, <handlerName>
Summary

Adds the named handler to the 'LiveCode' object within the current JavaScript context of the browser.

Introduced6.7
OSmac, windows
Platformsdesktop
Parameters
NameTypeDescription
instanceID

the ID of the browser instance returned by the revBrowserOpen function.

handlerName

the name of a LiveCode handler in the script of the card / stack displaying the browser.

Example
local tBrowserID
put revBrowserOpenCef(the windowId \
      of this stack, "http://www.livecode.com" ) into tBrowserID
revBrowserAddJavaScriptHandler tBrowserID, "myLiveCodeHandler"
RelatedCommand: revBrowserStop, revBrowserPrint, revBrowserSet, revBrowserMakeTextBigger, revBrowserNavigate, revBrowserRemoveJavaScriptHandler, revBrowserClose
Function: revBrowserOpen, revBrowserOpenCef
Message: browserOver, browserNewInstance, browserNewUrlWindow, browserDownloadRequest, browserNavigateCompleteFrame
Securitynetwork
Description

The revBrowserAddJavaScriptHandler adds the named handler to the 'LiveCode' object within the current JavaScript context of the browser.

The revBrowserAddJavaScriptHandler function will make the named LiveCode handler visible to JavaScript within the browser as a function belonging to the global JavaScript 'LiveCode' object. Calling this JavaScript function will result in a call to the LiveCode handler, which will be passed the browser instance as the first parameter followed by any parameters given to the JavaScript function.

A LiveCode card has the following handler:

on myLiveCodeHandler pID, pArg1, pArg2
    answer "Browser ID" && pID &&
    "called myLiveCodeHandler with arguments" && pArg1 && "and" && pArg2
end myLiveCodeHandler

Registered within the JavaScript context with the following command:

revBrowserAddJavaScriptHandler tBrowserID, "myLiveCodeHandler"

The JavaScript code within the browser can then call the LiveCode handler via the registered function:

if (tIsRevBrowser)
    liveCode.myBrowserHandler(tValue1, tValue2);