Method AddScriptMessageHandler
AddScriptMessageHandler(string)
Adds a script message handler with the given name.
public virtual bool AddScriptMessageHandler(string name)
Parameters
name
stringName of the message handler that can be used from Javascript.
Returns
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.