Table of Contents

Method AddScriptMessageHandler

Namespace
Alternet.UI
Assembly
Alternet.UI.Common.dll

AddScriptMessageHandler(string)

Adds a script message handler with the given name.

bool AddScriptMessageHandler(string name)

Parameters

name string

Name of the message handler that can be used from Javascript.

Returns

bool

true if the handler could be added, false if it could not be added.

Examples

bool ScriptMessageHandlerAdded = false;
ScriptMessageHandlerAdded = WebBrowser1.AddScriptMessageHandler("wx_msg");
if(!ScriptMessageHandlerAdded)
Log("AddScriptMessageHandler not supported");
if(ScriptMessageHandlerAdded)
WebBrowser1.RunScriptAsync(
"window.wx_msg.postMessage('This is a message body');");

Remarks

To use the script message handler from Javascript use window._name_.postMessage(_messageBody_) where _name_ corresponds the value of the name parameter. The _messageBody_ will be available to the application via a ScriptMessageReceived event.

The Edge backend only supports a single message handler and the IE backend does not support script message handlers.