> ## Documentation Index
> Fetch the complete documentation index at: https://docs.notifly.tech/llms.txt
> Use this file to discover all available pages before exploring further.

# Open WebView links in an external browser

> Configure a native app's WebView to open links from Notifly web popup buttons in an external browser.

> [!NOTE]
>
> This feature requires version 2.17.8 or later of the Notifly JS SDK, `@notifly-tech/notifly-js-sdk`.

## Overview

When you set a [web popup](https://docs.notifly.tech/en/user-guide/channel/web-message/guide.md) to **Open in external browser** in the Notifly console, the JS SDK opens the link with `target="_blank"`. In standard mobile browsers such as Chrome and Safari, no additional configuration is required.

A WebView in a native app needs native handling to open these links outside the WebView. Without that handling, the link can open in the same WebView or do nothing.

| Platform | Default behavior | Cause |
| - | - | - |
| Android WebView | Opens in the same WebView, or is ignored depending on the app's window handling | `setSupportMultipleWindows` defaults to `false` |
| iOS WKWebView | Tapping the link does nothing | No implementation of `WKUIDelegate`'s `createWebViewWith` method |

If your app displays Notifly web popups in a WebView, add the native configuration for your platform below.

> [!NOTE]
>
> If you use only the Notifly [Android SDK](https://docs.notifly.tech/en/developer-guide/android-sdk.md) or [iOS SDK](https://docs.notifly.tech/en/developer-guide/ios-sdk.md) to display in-app popups, the SDK already handles links. You do not need this additional configuration.

## Configure your platform

> [tab] Android
>
> Android WebView does not open `target="_blank"` links in an external browser automatically. Apply both steps below.
>
> ### Step 1. Enable multiple windows
>
> Configure the WebView to handle requests to open a new window.
>
> > [tab] Kotlin
> >
> > ```kotlin theme={null}
> > webView.settings.setSupportMultipleWindows(true)
> > webView.settings.javaScriptCanOpenWindowsAutomatically = true
> > ```
>
> > [tab] Java
> >
> > ```java theme={null}
> > WebSettings settings = webView.getSettings();
> > settings.setSupportMultipleWindows(true);
> > settings.setJavaScriptCanOpenWindowsAutomatically(true);
> > ```
>
> ### Step 2. Forward requests to open a new window
>
> After you enable multiple windows, tapping a `target="_blank"` link calls `WebChromeClient.onCreateWindow()`. In this method, capture the URL and pass it to the system URL handler. For web links, this normally opens the device's default browser.
>
> > [tab] Kotlin
> >
> > ```kotlin theme={null}
> > import android.content.Intent
> > import android.os.Message
> > import android.webkit.WebChromeClient
> > import android.webkit.WebResourceRequest
> > import android.webkit.WebView
> > import android.webkit.WebViewClient
> >
> > webView.webChromeClient = object : WebChromeClient() {
> >     override fun onCreateWindow(
> >         view: WebView, isDialog: Boolean,
> >         isUserGesture: Boolean, resultMsg: Message?
> >     ): Boolean {
> >         // Create a temporary WebView to intercept the URL.
> >         val tempWebView = WebView(view.context)
> >         tempWebView.webViewClient = object : WebViewClient() {
> >             override fun shouldOverrideUrlLoading(
> >                 view: WebView, request: WebResourceRequest
> >             ): Boolean {
> >                 // Open the intercepted URL with the system URL handler.
> >                 val intent = Intent(Intent.ACTION_VIEW, request.url)
> >                 view.context.startActivity(intent)
> >                 return true
> >             }
> >         }
> >         // Attach the temporary WebView through the transport object.
> >         val transport = resultMsg?.obj as? WebView.WebViewTransport
> >         transport?.webView = tempWebView
> >         resultMsg?.sendToTarget()
> >         return true
> >     }
> > }
> > ```
>
> > [tab] Java
> >
> > ```java theme={null}
> > import android.content.Intent;
> > import android.os.Message;
> > import android.webkit.WebChromeClient;
> > import android.webkit.WebResourceRequest;
> > import android.webkit.WebView;
> > import android.webkit.WebViewClient;
> >
> > webView.setWebChromeClient(new WebChromeClient() {
> >     @Override
> >     public boolean onCreateWindow(WebView view, boolean isDialog,
> >                                   boolean isUserGesture, Message resultMsg) {
> >         // Create a temporary WebView to intercept the URL.
> >         WebView tempWebView = new WebView(view.getContext());
> >         tempWebView.setWebViewClient(new WebViewClient() {
> >             @Override
> >             public boolean shouldOverrideUrlLoading(WebView v, WebResourceRequest request) {
> >                 // Open the intercepted URL with the system URL handler.
> >                 Intent intent = new Intent(Intent.ACTION_VIEW, request.getUrl());
> >                 v.getContext().startActivity(intent);
> >                 return true;
> >             }
> >         });
> >         // Attach the temporary WebView through the transport object.
> >         WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
> >         transport.setWebView(tempWebView);
> >         resultMsg.sendToTarget();
> >         return true;
> >     }
> > });
> > ```
>
> > [!NOTE]
> >
> > These examples use the `shouldOverrideUrlLoading(WebView, WebResourceRequest)` overload, which requires Android 7.0 (API level 24) or later. If your app already uses a `WebChromeClient`, add `onCreateWindow()` to that class.

> [tab] iOS
>
> When you tap a `target="_blank"` link, WKWebView calls the `createWebViewWith` method of its `WKUIDelegate`. Without an implementation of this method, the link is ignored. No additional WebView settings are required.
>
> Set `webView.uiDelegate = self` if it is not already set, and add the `createWebViewWith` method below. Returning `nil` prevents the creation of a new WKWebView. `UIApplication.shared.open` passes the URL to the system, which opens web links in the default browser or the associated app.
>
> ```swift theme={null}
> // MARK: - WKUIDelegate
> extension YourViewController: WKUIDelegate {
>     func webView(
>         _ webView: WKWebView,
>         createWebViewWith configuration: WKWebViewConfiguration,
>         for navigationAction: WKNavigationAction,
>         windowFeatures: WKWindowFeatures
>     ) -> WKWebView? {
>         // Open the target="_blank" link outside the WebView.
>         if let url = navigationAction.request.url {
>             UIApplication.shared.open(url)
>         }
>         return nil
>     }
> }
> ```

## How it works

With this configuration, links open outside the WebView as follows.

1. A user taps a button in a Notifly web popup. The JS SDK opens the link with `target="_blank"`.
2. The WebView delegates the request to open a new window to native code through `onCreateWindow` on Android or `createWebViewWith` on iOS.
3. Native code extracts the URL and passes it to the system URL handler, which normally opens web links in the device's default browser, such as Chrome or Safari.

## Notes

* This configuration applies only when the message's link opening mode is **Open in external browser** in the Notifly console. With the default mode, **Open in current window**, links open inside the WebView regardless of this configuration.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.