Sdílet prostřednictvím


WebView.WebResourceRequested Event

Definition

Occurs when an HTTP request has been made.

// Register
event_token WebResourceRequested(TypedEventHandler<WebView, WebViewWebResourceRequestedEventArgs const&> const& handler) const;

// Revoke with event_token
void WebResourceRequested(event_token const* cookie) const;

// Revoke with event_revoker
WebView::WebResourceRequested_revoker WebResourceRequested(auto_revoke_t, TypedEventHandler<WebView, WebViewWebResourceRequestedEventArgs const&> const& handler) const;
public event TypedEventHandler<WebView,WebViewWebResourceRequestedEventArgs> WebResourceRequested;
function onWebResourceRequested(eventArgs) { /* Your code */ }
webView.addEventListener("webresourcerequested", onWebResourceRequested);
webView.removeEventListener("webresourcerequested", onWebResourceRequested);
- or -
webView.onwebresourcerequested = onWebResourceRequested;
Public Custom Event WebResourceRequested As TypedEventHandler(Of WebView, WebViewWebResourceRequestedEventArgs) 
<WebView WebResourceRequested="eventhandler"/>

Event Type

Windows requirements

Device family
Windows 10, version 1809 (introduced in 10.0.17763.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v7.0)

Examples

This example demonstrates how to intercept request for a specific domain generate an alternate response.

Uri _myUri = new Uri("http://www.contoso.com");

void InterceptWebRequest(WebView sender, WebResourceRequestedEventArgs args)
{
    if (_myUri.IsBaseOf(args.Request.RequestUri))
    {
        args.Response = GenerateResponse(args.Request);
    }
}

HttpResponseMessage GenerateResponse(HttpRequestMessage request)
{
    // ...
}

Remarks

This event occurs after the HTTP request has been made. You can use this event to intercept the response before it's processed by the WebView.

Applies to