Contents

webView(_:decidePolicyFor:decisionHandler:)

Asks the delegate for permission to navigate to new content based on the specified action information.

Declaration

optional func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping @MainActor @Sendable (WKNavigationActionPolicy) -> Void)
optional func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction) async -> WKNavigationActionPolicy

Parameters

  • webView:

    The web view from which the navigation request began.

  • navigationAction:

    Details about the action that triggered the navigation request.

  • decisionHandler:

    A completion handler block to call with the results about whether to allow or cancel the navigation. This handler has no return value and takes the following parameter:

    policy

    A constant that indicates whether to cancel or allow the navigation. For a list of possible values, see Wknavigationactionpolicy.

Mentioned in

Discussion

Use this method to allow or deny a navigation request that originated with the specified action. The web view calls this method after the interaction occurs but before it attempts to load any content. If you implement this method, always execute the decisionHandler block at some point. You may execute it synchronously from your delegate method’s implementation, or execute it asynchronously after your method returns.

If your delegate object implements the webView(_:decidePolicyFor:preferences:decisionHandler:) method, the web view doesn’t call this method.

See Also

Allowing or denying navigation requests