> ## 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.

# Dynamic titles

> Set the text or image in your app's top navigation bar per URL, at build time in App Studio or at runtime with the JavaScript Bridge.

Configure the text that shows in the top navigation bar, either at build time through your app configuration or at run time through the JavaScript Bridge.

![iOS top navigation bar showing a page title](https://mintcdn.com/median-co/TpSItjrYpkPK-i0N/images/docs/assets/-MHABc_2IZgrLlHqPfUS/-MHC8SFE1rWpxISQhUwb/-MHCAGZu9i7szcxvXZAX/Screen-Shot-2020-09-14-at-8.12.54-AM.png?fit=max\&auto=format\&n=TpSItjrYpkPK-i0N\&q=85\&s=811607a136a472a0ca28c9b1937ec777)

iOS navigation bar example

## Implementation guide

### App configuration

You may specify text titles or set image display for different URLs in the **Dynamic Titles** options within the **Native Top Navigation Bar** section of App Studio.

For a given URL rule, if "Text" is selected the text provided will be displayed. Otherwise, if "Image" is selected the top nav bar image will be displayed.

Rules are prioritized from top to bottom. If no match is found, your app name will be shown.

An example JSON formatting for BooyaFitness.com is provided below:

```json JSON theme={null}
[
    {
        "regex": "https://www.booyafitness.com/",
        "showImage": true
    },
    {
        "regex": "https://www.booyafitness.com/dashboard",
        "title": "Dashboard"
    },
    {
        "regex": "https://www.booyafitness.com/edit",
        "title": "Account"
    },
    {
        "regex": "https://www.booyafitness.com/password/new",
        "title": "Recover Password"
    },
    {
        "regex": "https://www.booyafitness.com/workouts/browse",
        "title": "Workouts"
    },
    {
        "regex": "https://www.booyafitness.com/partners/browse",
        "title": "Partners"
    },
    {
        "regex": "https://www.booyafitness.com/pricing",
        "title": "Pricing"
    }
]
```

A default navigation title can be defined in the app configuration that is then overwritten dynamically as required. Or alternatively, the configuration can be left blank and all titles set at runtime by your website.

> [!TIP]
>
> **Use your AI agent**
>
> Use the Median MCP with your AI agent to show a custom title or your logo in the top navigation bar of your mobile app. See
> [Median MCP server](https://docs.median.co/docs/mcp-server.md) to set it up.

### JavaScript Bridge

Create your navigation title structure, and then run the `median.navigationTitles.set()` JavaScript Bridge function to set the values. To set the example navigation title run the following:

Median JavaScript Bridge

```javascript JavaScript theme={null}
var menuItems = {
    active: true,
    titles: [{
      showImage: true,
      regex: '/home'
   },{
      title: 'my title',
      regex: '.*'
   }]
}
median.navigationTitles.set({
  'persist':true,
  'data': menuItems});
```

**Parameters**

**persist** `boolean`

Set to `true` to save the navigation titles for the next time the app launches. Otherwise, they only take effect for the current session.

**data** `object`

The navigation titles. Leave it out to go back to the titles configured at build time, as shown below.

**properties**

**active** `boolean`

Set to `true` to use these titles.

**titles** `object[]`

The title rules, checked from top to bottom.

**properties**

**regex** `string`

Regular expression matched against the page URL.

**title** `string`

Text to show as the title.

**showImage** `boolean`

Set to `true` to show the top navigation bar image instead of text.

To revert the navigation titles to the configuration set at build time, run the following command:

Median JavaScript Bridge

```javascript JavaScript theme={null}
if (navigator.userAgent.indexOf('median') > -1) {
    median.navigationTitles.set({'persist':true});
}
```

For a one-off setting of the current page's title, URL encode the desired title and run the following command:

Median JavaScript Bridge

```javascript JavaScript theme={null}
if (navigator.userAgent.indexOf('median') > -1) {
    median.navigationTitles.setCurrent({'title':'Hello%20World'})
}
```

```html HTML theme={null}
<a onclick="gonative.navigationTitles.setCurrent({'title':'Hello%20World'})">Set Current Page's Title</a>
```

**Parameters**

**title** `string`

The title for the current page, URL encoded.

### Set a title image at runtime

Show an image in place of the title, such as a logo for the signed-in user's organization.

**Parameters**

Pass either `url` or `image`.

**url** `string`

Image URL. The app downloads it, so the server doesn't need to allow cross-origin requests. Relative URLs are resolved against the current page.

**image** `Blob | string`

Image data from your page: a `Blob`, a data URL, or a base64 string.

Use a PNG, JPEG, or WebP image. SVG images aren't supported.

The image is scaled to the same height as the top navigation bar image set in App Studio, and keeps its aspect ratio. It replaces any title or image already showing.

The image applies to the [navigation instance](https://docs.median.co/docs/navigation-instances.md) that matches the current page, and shows again whenever the user returns to a page of that instance. If your app doesn't use instances, it applies to every page. It stays until you reset it or the app restarts.

> [!TIP]
>
> **Developer Demo**
>
> Display our demo page in your app to test during development [https://median.dev/title-image ](https://median.dev/title-image)

Median JavaScript Bridge

```javascript URL theme={null}
median.navigation
  .setTitleImage({ url: "https://example.com/images/logo.png" })
  .catch((error) => console.log(error.code, error.message));
```

```javascript Blob theme={null}
const response = await fetch("/images/logo.png");
const blob = await response.blob();

median.navigation
  .setTitleImage({ image: blob })
  .catch((error) => console.log(error.code, error.message));
```

```javascript Reset theme={null}
median.navigation.resetTitleImage();
```

`resetTitleImage()` goes back to the title or image configured at build time.

Both methods return a promise. It resolves when the call succeeds, and rejects with an error object if setting the image fails.

**Response**

**success** `boolean` *required*

`true` when the call succeeds.

**Error**

**code** `string` *required*

The error code. See the table below.

**message** `string` *required*

A description of the error.

```json JSON theme={null}
{
  "code": "NETWORK_ERROR",
  "message": "Download failed with HTTP 404"
}
```

If you pass a `callback` function instead, it receives `{ success: false, error: { code, message } }` on failure.

| Error code | Cause |
| - | - |
| `INVALID_PARAMETERS` | Neither `url` nor `image` was passed, or `url` isn't a valid URL. |
| `NETWORK_ERROR` | The image couldn't be downloaded. |
| `INVALID_IMAGE` | The data isn't valid base64 or isn't an image the device can display. |


## Related topics

- [Top navigation bar demo app](https://docs.median.co/docs/top-nav-bar-demo-app.md)
- [Top navigation bar](https://docs.median.co/docs/top-navigation-bar.md)
- [Changelog archive](https://docs.median.co/docs/changelog-archive.md)


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