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

# Auto new windows

> Open pages in new windows with a Back button for multi-level navigation, configured in App Studio or at runtime with the JavaScript Bridge.

Many widely used apps ranging from news apps to banking apps provide a hierarchical or multi-level navigation experience for users. This allows users to view specific page(s) and easily return to the same place on the prior page by way of a "\< Back" button in the top navigation bar.

For example, a news app may have various categories such as "Local News", "International", "Business", "Sports", "Lifestyle" defined as level 2. When a user clicks a category, they will see news articles in that category which they can open and browse. At any time they can press "\< Back" in the top nav bar to return to the front page.

Median allows you to configure this user experience easily by assigning individual pages or groups of pages to a Level by creating rules. When clicking a link to a page that has been assigned a higher level, the link will open in a new window within the app. The top navigation bar will show a "\< Back" button on the left to allow easy navigation to the lower level page even if the user has navigated elsewhere in that current level. The top navigation bar will show the page name in the center but this can be changed using the [Dynamic Titles](https://docs.median.co/docs/dynamic-titles.md) configuration.

See below for an example.

![Tapping a link opens the page in a new window with a Back button in the top navigation bar](https://mintcdn.com/median-co/7LCOHMhgIef7ewYE/images/docs/83ec6e7f125aa0114a3a7d8352a7e16d84a69303bfb65c5dda3a530671680d25-autonewwindows.gif?s=b155bf58d00b92272fdd4a067960a94e)

Auto new windows example

> [!WARNING]
>
> **Navigation history**
>
> When a page that is assigned a higher level opens in a new window within your app, it will not have the navigation history of the prior page. This means functionality such as swipe gestures will only take the user back to the originally opened URL for that window.

## Defining a navigation hierarchy for auto new windows

You may define the navigation hierarchy for your app at build time within your app configuration or alternatively at run time from your website via the JavaScript Bridge.

### App configuration

Whenever a user navigates to a URL that matches a higher level rule, the page will load in a new window (Android Activity or iOS ViewController). Rules are prioritized top to bottom. If no match is found for a link, the link will open in the current level.

> [!WARNING]
>
> **Single-page apps**
>
> Auto new windows will load the new page in a new webview, and requires a full page load. For example, if your site is a single-page app driven by AJAX, then you may need to force a full page load using something like: `window.location.href = 'https://my-ajax-site/path';`

### JavaScript Bridge

Auto new windows can be set dynamically from your website using the Median JavaScript Bridge. A default auto new windows setting can be defined in App Studio that is then overwritten dynamically as required. Or alternatively, the configuration can be left blank in App Studio and the auto new windows configuration set by your website.

To configure auto new windows settings, define your navigation levels structure as a JSON object and run the following command:

Median JavaScript Bridge

```javascript JavaScript theme={null}
var autoNewWindowsRules = {
    active: true,
    persist: true,
    levels: [{
      regex: '.*median.*',
      level: 2
    }, {
      regex: '.*',
      level: 1
    }]
};

median.navigationLevels.set(autoNewWindowsRules);
```

Setting `persist: true` will save the navigation levels for use the next time the app is launched, otherwise, the changes will only take effect for the current app session.

To revert to the appConfig.json definition built into your app, run the following command:

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.navigationLevels.set({persist: true});
```

## Auto new windows demo app

```json Auto new windows configuration theme={null}
/* Auto new windows configuration */
[
  {
    "regex": "https://median.dev/auto-new-windows/index.html/?",
    "level": 1
  },
  {
    "regex": "https://median.dev/auto-new-windows/contact.html/?",
    "level": 2
  },
  {
    "regex": "https://median.dev/auto-new-windows/about.html/?",
    "level": 3
  }
]
```

```javascript Set auto new windows theme={null}
/* Set auto new windows */
median.navigationLevels.set({
  active: true,
  levels: [{
    regex: "https://median.dev/auto-new-windows/index.html/?",
    level: 1
  }, {
    regex: "https://median.dev/auto-new-windows/contact.html/?",
    level: 1
  }, {
    regex: "https://median.dev/auto-new-windows/about.html/?",
    level: 2
  }],
  persist:true
});
```

```javascript Revert auto new windows theme={null}
/* Revert auto new windows */
if (navigator.userAgent.indexOf('median') > -1) {
  median.navigationLevels.set({ persist: true });
}
```


## Related topics

- [New windows](https://docs.median.co/docs/new-windows.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.