WebView.ScriptNotify event

2 out of 5 rated this helpful - Rate this topic

Occurs when the content contained in the WebView control passes a string to the application by using JavaScript.

Syntax


public event NotifyEventHandler ScriptNotify


<WebView ScriptNotify="eventhandler"/>


Event information

Delegate NotifyEventHandler

Remarks

ScriptNotify enables the hosted HTML page to fire this event to the XAML app when the page calls window.external.notify and passes a string parameter. If content is loaded into the WebView control using the Navigate method, the app must opt-in to receiving ScriptNotify events by using the AllowedScriptNotifyUris property, which has the list of URIs that can fire ScriptNotify. If the content is loaded using NavigateToString, the application will receive ScriptNotify events without the opt-in. Set the AllowedScriptNotifyUris property to the value returned by the AnyScriptNotifyUri property to indicate that any page can fire ScriptNotify events to this WebView control.

Examples

The following code example demonstrates the use of the ScriptNotify event.


public MyPage()
{
    this.InitializeComponent();
    MyWebView.ScriptNotify += MyWebView_ScriptNotify;

    // Here we have to set the AllowedScriptNotifyUri property because we are 
    // navigating to some site where we don't own the content and we want to 
    // allow window.external.notify() to pass data back to the app.
    List<Uri> allowedUris = new List<Uri>();
    allowedUris.Add(new Uri("http://www.bing.com"));
    MyWebView.AllowedScriptNotifyUris = allowedUris;
}

void MyWebView_ScriptNotify(object sender, NotifyEventArgs e)
{
    // Respond to the script notification.
}


Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Namespace

Windows.UI.Xaml.Controls
Windows::UI::Xaml::Controls [C++]

Metadata

Windows.winmd

See also

WebView
AllowedScriptNotifyUris

 

 

Build date: 3/12/2013

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.