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

# Link behavior

> Control whether links open inside your app, in an in-app browser, or externally, using App Studio rules or the JavaScript Bridge.

URLs in your app can be loaded in three ways:

* **Internally** within your app, for app-optimized web content.
* Within an **in-app browser** window, for sites that are not ideal inside the main WebView (for example external websites). When the user closes the embedded browser, focus returns to your app, which helps session time and reduces bounce.
* **Externally** in the device default mobile browser or the default app registered for a deep link (for example, Safari, Chrome, Google Maps, or LinkedIn). Use this for fully external content, especially third-party destinations where you have limited control and want a clear separation between your app and the external experience. Users always leave your app when a link opens externally.

> [!TIP]
>
> **Test  with our demo page**
>
> We host a ready-made demo page at
>
> that calls the  features through the Median JavaScript Bridge.
> Load it inside your Median app during development, either by setting it
> as your app's website URL in App Studio or by navigating to it from your
> own site, and use it to confirm  works on a real device before
> you add it to your own pages.
>
> The demo page only works inside a Median app with  enabled.
> Opened in a regular mobile or desktop browser, the native features
> won't respond. Remember to switch your app back to your own URL before
> release.

### In-app browser (reference)

<table>
  <thead>
    <tr>
      <th />

      <th>iOS</th>
      <th>Android</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        **Initial view**
      </td>

      <td>
        ![iOS in-app browser when it first opens](https://mintcdn.com/median-co/yvThAkXSLqPa6nzP/images/docs/docs/in-app-browser/ios.png?fit=max\&auto=format\&n=yvThAkXSLqPa6nzP\&q=85\&s=1dcdb3c9dc86313c8d936a5513b8158c)
      </td>

      <td>
        ![Android in-app browser when it first opens](https://mintcdn.com/median-co/yvThAkXSLqPa6nzP/images/docs/docs/in-app-browser/android.png?fit=max\&auto=format\&n=yvThAkXSLqPa6nzP\&q=85\&s=4ad5282b79c14b88306c7a41d60c7b51)
      </td>
    </tr>

    <tr>
      <td>
        **After scroll / menu**
      </td>

      <td>
        ![iOS in-app browser after scroll](https://mintcdn.com/median-co/yvThAkXSLqPa6nzP/images/docs/docs/in-app-browser/ios-scroll.png?fit=max\&auto=format\&n=yvThAkXSLqPa6nzP\&q=85\&s=9cc047725d708790ba9a055f1533b29d)
      </td>

      <td>
        ![Android in-app browser context menu](https://mintcdn.com/median-co/yvThAkXSLqPa6nzP/images/docs/docs/in-app-browser/android-context-menu.png?fit=max\&auto=format\&n=yvThAkXSLqPa6nzP\&q=85\&s=4191fcbdd3c8c72d9668b002be5665ab)
      </td>
    </tr>
  </tbody>
</table>

On iOS you can set the color of native in-app browser controls from **App Studio → Branding**.

### In-app browser closed callback

You can detect when a user closes the in-app browser by defining `median_appbrowser_closed`. The app calls this function automatically when the in-app browser closes.

Median JavaScript Bridge

```javascript JavaScript theme={null}
function median_appbrowser_closed() {
  console.log("App browser closed!");
}
```

## Opening links

Regular links on a page follow the **link handling rules** configured for your app. You can also open URLs programmatically with the JavaScript Bridge.

### JavaScript Bridge: open modes

When opening a URL through the JavaScript Bridge, use one of the following modes:

* `blank` - New WebView window instance (default when mode is omitted).
* `internal` - Current WebView window instance.
* `external` - Mobile browser or the app registered for the URL’s deep link.
* `appbrowser` - In-app browser window (see screenshots above).

Median JavaScript Bridge

```javascript JavaScript  theme={null}
// Modes: "blank" (default), "internal", "external", or "appbrowser" 
median.window.open("https://median.co", "appbrowser"); 
```

### Link handling rules

Regular web links open according to the rules defined in your app. The default configuration works for many apps; you can adjust the rule set as needed.

**Default for “All Other Links” is App Browser**

By default, links to URLs on the **same domain** as your Website URL open **Internal** in your app. Links on **other** domains open in the **App Browser**. To change that, scroll to the bottom of the Link Behavior rules, edit the **All Other Links** rule, and set it to **Internal** (everything stays in the main WebView) or **External** (open in the system browser or default app).

**Order matters**

Rule matching is evaluated **top to bottom**. Put the **most specific** rules first and the **most general** rules last.

#### Editing a rule

To edit a rule, select the **Edit** control on the rule. Choose how the rule should match URLs:

| Match type | Behavior |
| - | - |
| **Single Page** | Apply to one specific URL you enter. |
| **Multiple Pages** | Apply using a URL path prefix. |
| **All Pages** | Apply the rule across the entire app. |
| **Custom** | Supply your own URL pattern. |

Toggle **Include Subdomains** to extend the rule to subdomains of the matched domain.

To match arbitrary domains with a query flag, use a URL pattern such as `https?:\/\/.*\?external=true` and link to URLs like `https://anysite.com/page?external=true`.

#### Test regular expressions

* [RegExr](http://www.regexr.com/)

* [regex101](https://regex101.com/)

> [!WARNING]
>
> **URL pattern compatibility**
>
> Lookahead and lookbehind expressions, including negative variants, **are not supported on Android** and are only available **on iOS 14 and later**. Rules using these patterns will silently fail to match on unsupported platforms. Use simple, positive regular expressions to ensure consistent behavior across both platforms.

> [!TIP]
>
> **Use your AI agent**
>
> Use the Median MCP with your AI agent to add link handling rules to your app. See
> [Median MCP server](https://docs.median.co/docs/mcp-server.md) to set it up.

#### Changing rules at runtime

To apply new internal, external, and app browser rules at runtime, run the following JavaScript Bridge command:

Median JavaScript Bridge

```javascript JavaScript theme={null}
var rulesArray = [
  {
    id: 1,
    regex: "https?://maps\\.google\\.com.*",
    mode: "external",
  },
  {
    id: 2,
    regex: "https?://([-\\w]+\\.)*google\\.com/maps/search/.*",
    mode: "external",
  },
  {
    id: 3,
    regex: "https?://([-\\w]+\\.)*linkedin\\.com/.*",
    mode: "external",
  },
  {
    id: 4,
    regex: "https?://([-\\w]+\\.)*nytimes\\.com/.*",
    mode: "appbrowser",
  },
  {
    id: 5,
    regex: "https?://([-\\w]+\\.)*wsj\\.com/.*",
    mode: "appbrowser",
  },
];

median.internalExternal.set({ rules: rulesArray });
```

## Context menu

The **context menu** is a floating menu shown when the user **long-presses a link**. You can turn it on or off at runtime and choose which actions appear, using the JavaScript Bridge.

> [!TIP]
>
> **Test  with our demo page**
>
> We host a ready-made demo page at
>
> that calls the  features through the Median JavaScript Bridge.
> Load it inside your Median app during development, either by setting it
> as your app's website URL in App Studio or by navigating to it from your
> own site, and use it to confirm  works on a real device before
> you add it to your own pages.
>
> The demo page only works inside a Median app with  enabled.
> Opened in a regular mobile or desktop browser, the native features
> won't respond. Remember to switch your app back to your own URL before
> release.

### Enable or disable

Median JavaScript Bridge

```javascript JavaScript theme={null}
  median.contextMenu.setEnabled(true); // or false to disable
```

### Set available actions

Median JavaScript Bridge

```javascript JavaScript  theme={null}
// Define which actions appear in the context menu
median.contextMenu.setActions(["copyLink", "openExternal"]); 
```

### Supported actions

* `copyLink`: Copies the selected link to the clipboard.
* `openExternal`: Opens the selected link in the device’s external browser.

### UI preview

| iOS | Android |
| - | - |
| ![Context menu on iOS](https://mintcdn.com/median-co/yvThAkXSLqPa6nzP/images/docs/docs/context-menu/context-ios.gif?s=283ddcd983e0cb1f58c191eab8c3644e) | ![Context menu on Android](https://mintcdn.com/median-co/yvThAkXSLqPa6nzP/images/docs/docs/context-menu/context-android.gif?s=f38686b39fdb9b3c7dcf81d86390918d) |


## Related topics

- [Link handling overview](https://docs.median.co/docs/link-handling-overview.md)
- [Changelog archive](https://docs.median.co/docs/changelog-archive.md)
- [Changelog](https://docs.median.co/docs/changelog.md)


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