ifHTMLWidgetEvent
GetData() As roAssociativeArray
Returns the event data as an associative array with the following key/value pairs:
[string] reason
: The cause of the event, which can be one of the following:"load-started"
: The HTML widget has started loading a page."load-finished"
: The HTML widget completed loading a page."load-error"
: The HTML widget failed to load a page. Use theuri
key to identify the failing resource and themessage
key to retrieve some explanatory text."download-request"
: The HTML widget instance has received a download request. The Chromium instance does not process download requests for MIME types it doesn't recognize (e.g. PDFs); instead, it passes this event, along with themime-type
andurl
parameters to the BrightScript autorun for processing."new-window-request"
: The HTML widget instance has received a request to open a URI in a new window. This request will normally come from HTML anchors with"target=_blank"
/"target=_top"
or the JavaScriptWindow.open()
method. The requested URI is specified in theuri
parameter.
[string] uri
: The URI of the failing resource or new-window request (applicable forreason:"load-error"
orreason:"new-window-request"
)[string] message
: Explanatory text related to the load failure (applicable forreason:"load-error"
only)[string] mime-type
: The MIME type of the download request (applicable forreason:"download-request"
only)[string] url
: The URL of the download request (applicable forreason:"download-request"
only)
Example
The following event loop waits for an HTML widget event. If the event indicates that a PDF download request has been received, the script passes the relevant data to a CreatePdfRenderer() function that is not defined here:
while true ev = wait(0, gaa.mp) print "=== BS: Received event ";type(ev) if type(ev) = "roHtmlWidgetEvent" then eventData = ev.GetData() if type(eventData) = "roAssociativeArray" and type(eventData.reason) = "roString" then if eventData.reason = "load-error" then print "=== BS: HTML load error: "; eventData.message else if eventData.reason = "load-finished" then print "=== BS: Received load finished" receivedLoadFinished = true else if eventData.reason = "message" then ' To use this: msgPort.PostBSMessage({text: "my message"}); else if eventData.reason = "load-started" then print "=== BS: Received load started" else if eventData.reason = "download-request" then print "=== BS: Received a download request" if eventData.mime_type = "application/pdf" then CreatePdfRenderer("file:///index.html?file=" + eventData.url) endif else print "======= UNHANDLED HTML EVENT =========" print eventData.reason endif else print "=== BS: Unknown eventData: "; type(eventData) endif endif endwhile