# Pop-up windows that open as soon as a page loads

Source: https://easeweb.dev/learn/pop-up-windows
Topics: Keyboard and focus > The page changes only when the user asks (WCAG 3.2.5)
The fix: Don't open a window as the page loads. Either put what it showed on the page itself, such as the offer as a section after the courses, or open it from a link people press that says it opens a new window.
Test with: keyboard, screen reader, zoom
References: https://www.w3.org/WAI/WCAG22/Understanding/change-on-request.html https://www.w3.org/WAI/WCAG22/Techniques/failures/F52 https://www.w3.org/WAI/WCAG22/Techniques/failures/F22 https://www.w3.org/WAI/WCAG22/Techniques/client-side-script/SCR24 https://www.w3.org/WAI/WCAG22/Techniques/html/H83 https://developer.mozilla.org/en-US/docs/Web/API/Window/open https://support.google.com/chrome/answer/95472

This is a recreated teaching example, not a finding about a named client. The code is a starting pattern: test it in your own product. No completed assistive-technology test is claimed here.

## What happens

Wrenhill, an online course site, plays its lessons in a pop-up player. Browsers block pop-ups by default and let people allow them for one site, so Wrenhill's help pages ask people to allow pop-ups for it, and many do. For the spring sale, the marketing team adds a script to the My courses page that opens the offer in a small window, 480 by 600 pixels, as soon as the page has loaded.

A screen reader user signs in and follows the link to My courses, to carry on with Watercolour basics. The page loads, and at once the offer opens in a new window over it and takes focus. The screen reader reads the new window: "Spring offer – Wrenhill", then the offer's heading. Tab moves through the offer's links. Nothing says that My courses is open behind the window, and the window has no page before it to go back to. To reach their course, they have to close a window they never opened, or switch windows, and then find their place on My courses again. It happens every time they open the page.

People who left the pop-up blocker on for the site see none of this: the browser stops the window, and Chrome shows a small "Pop-up blocked" mark in the address bar. The window reaches exactly the people who allowed pop-ups to use the lessons.

## Why it fails

Success Criterion 3.2.5 Change on Request (Level AAA) asks that changes of context happen only when people ask for them, or that people can turn such changes off. WCAG counts a change of viewport or of focus as a change of context, and a new window is both: a new window appears, and focus moves into it. Following a link asked for My courses; it didn't ask for a second window. W3C names this failure F52, a new window opened as soon as a new page is loaded, and its test is the scene above: load the page, and check whether a new window opened and was given focus. Its example opens an advertisement from a load handler. F22, windows that people didn't ask for, describes the same moment from the other side: someone goes to a page, and a new window appears over it and takes focus.

Nothing in the browser stops the page from asking. `window.open()` may be called at any time; what stops most of these windows is the browser's pop-up blocker, which, as MDN puts it, lets pop-ups open only in direct response to user input. The blocker is a setting in each person's browser, not part of the page, so it doesn't make the page pass: the people who allowed pop-ups for this site get the window.

The sufficient techniques for windows under 3.2.5 both open them on request and say so first: H83 with the link's `target` and words in the link text, and SCR24 with a script on a link that says it opens a new window and falls back to the same tab when no window can open.

## Who is affected

On a phone, where the browser shows one page at a time, the offer takes the whole screen, and My courses is out of sight behind it.

## What automation and AI miss

There is nothing wrong in the markup, and axe has no rule for it. Browsers block pop-ups by default, so a tester clicking through may never see the window either. The audit adds a script to every page before the page's own scripts run. It notes each `window.open()` call made while the page loads, or in the three seconds after, before anything has been pressed, whether in a load or DOMContentLoaded handler or in a script that runs as the page is parsed, and sends it to review as `ew:window-on-load-manual-check`, with where the window would go. It notes the call even when the browser stops the window. Only a person can check whether the window opens on every visit and what it holds. A window opened later, after a longer delay or when people scroll, isn't noted. An online pop-up window generator offers "Page onload" as a trigger beside a link or a button click, and AI coding tools asked to "show the offer to everyone who visits" can write the load handler in the Before.

## Before: a script that opens the offer as the page loads

```html
<main>
  <h1>My courses</h1>
  <ul class="courses">
    <li>
      <a href="/courses/watercolour">Watercolour basics</a>
      Lesson 4 of 10
    </li>
    …
  </ul>
</main>
<script>
  window.addEventListener('load', () => {
    window.open('/offers/spring', 'offer', 'width=480,height=600');
  });
</script>
```

- A window nobody asked for opens: as soon as the page has loaded, the script opens the offer in a new window, before anyone has pressed anything.
- People are pulled away from the page they opened: the new window takes focus, so the screen reader, the keyboard and the magnifier go to the offer, not to My courses.
- People can't see it coming or stop it: nothing on My courses says that a window will open, and nothing turns it off.

## After: the offer on the page itself

```html
<main>
  <h1>My courses</h1>
  <ul class="courses">
    <li>
      <a href="/courses/watercolour">Watercolour basics</a>
      Lesson 4 of 10
    </li>
    …
  </ul>
  <section aria-labelledby="offer-title">
    <h2 id="offer-title">Spring offer</h2>
    <p>30% off every course until 31 March.</p>
    <a href="/courses">Browse courses</a>
  </section>
</main>
```

1. Delete the script. Nothing opens as the page loads, and focus stays on My courses, the page people asked for.
2. Put what the window showed in a section of the page, with its own heading, after the courses. People meet the offer as they read or Tab through the page, and move past it when they don't want it, without anything coming between them and their courses.
3. Keep its link a plain link, opening in the same tab. It changes the page only when people press it, and Back brings them back.

This fixes the Before and passes 3.2.5: there is no window, so there is no change of context at all.

## After: a link that says it opens a new window

```html
<main>
  <h1>My courses</h1>
  <ul class="courses">
    <li>
      <a href="/courses/watercolour">Watercolour basics</a>
      Lesson 4 of 10
    </li>
    …
  </ul>
  <p>
    <a href="/offers/spring" id="offer-link">See the spring offer (opens in a new window)</a>
  </p>
</main>
<script>
  const offerLink = document.getElementById('offer-link');
  offerLink.addEventListener('click', (event) => {
    const opened = window.open(offerLink.href, 'offer', 'width=480,height=600');
    if (opened) event.preventDefault();
  });
</script>
```

1. Delete the load handler, and put a link to the offer on the page, after the courses, with "(opens in a new window)" in its words. Everyone reads or hears that before they press it, and a screen reader hears "See the spring offer (opens in a new window), link".
2. Open the window from the link's click handler. Pressing Enter on a focused link fires it too, so it works from the keyboard, and since the window follows a press, the pop-up blocker lets it open.
3. Cancel the link's own action only when a window opened. Where a blocker or a setting stops the window, `window.open()` returns `null`, and the link opens the offer in the same tab, as any link does.

This follows technique SCR24, with the warning written in the link's text rather than added by the script. It fixes the Before and passes 3.2.5: the window opens only when someone asks for it, and the link says so first.

## Which option to use

Both pass 3.2.5. The offer on the page is recommended: with no window at all, there is nothing to warn about, every visitor sees the offer whatever their pop-up setting and on a phone, and there is no script to write. Today the window reaches only the people who allowed pop-ups, so moving the offer onto the page is also the way to show it to everyone else. Keep a window, behind the link, only for something people want beside the page while they use it, such as a lesson player or a reference to read while they work, and then say so in the link's words.

## Implementation decisions

**Scripts the site doesn't write.** The call is often not in the site's own code. A marketing, survey or advertising tool added through a tag manager can open its window on page view, and its setting may be called "on page load" or "on entry". Search the tag manager's tags and each tool's display settings as well as the site's scripts, and set them to open on a click, or show their content in the page.

**A window opened behind the page is not a fix.** A pop-under, opened and then sent behind the page, doesn't take focus as the page loads, but it is still a window nobody asked for, which F22 covers. People find it later, when they close the page, with nothing to say where it came from.

**Once per visit is not a fix.** A cookie that opens the window only on the first visit still opens it on that visit, before anyone has asked, and again for people who clear their cookies or use another device.

**Asking first in a pop-up inside the page.** A dialog that opens as the page loads, asking whether people want to see the offer, moves the interruption into the page instead of removing it; [timed pop-ups that open while you read or type](/learn/timed-pop-ups) covers those.

**Ctrl, Command and Shift with a click.** A click with Ctrl, Command or Shift held asks the browser for a new tab or window of the person's own choosing. Let those through by returning from the handler before `window.open()` when `event.ctrlKey`, `event.metaKey` or `event.shiftKey` is set.

**No `noopener` in the features.** With `noopener` in the third argument, `window.open()` returns `null` even when the window opened, so the handler above would also open the offer in the same tab. A window on the site's own pages doesn't need it.

**A link in the same tab.** A plain link to the offer page, with no window and no script, passes as well and keeps Back working; it needs no warning. [Links that open a new tab without saying so](/learn/new-tab-links) covers when a new tab is worth keeping.

## Verify the fix

1. Search the site's scripts, the tag manager's tags and the settings of each marketing, survey and advertising tool for `window.open()` and for "on page load" or "on entry" triggers. Each call runs only in the click handler of a link or button that says it opens a new window.
2. Allow pop-ups for the site in the browser, open each page with the keyboard and leave it alone for a minute. No new window or tab opens, and focus stays on the page.
3. With a screen reader, open the page: the first thing read is the page you opened. Move to the link and hear "(opens in a new window)" before you press it.
4. Press the link: the window opens. Close it and check that you are back on the page, on the link. Block pop-ups for the site and press it again: the offer opens in the same tab.

Record the OS, browser and assistive-technology versions, the build, the date, and the actual result of each step. Repeat after the page's scripts, the tag manager's tags or a marketing tool's settings change.

## Limits

This is a starting pattern, not a guarantee for every page. It covers a window opened as a page loads. A window opened when text is typed into a field, or a page that changes when people leave a field, fails the same criterion in another way and isn't covered here; a field or select that changes the page as soon as it is focused or changed is [dropdowns and fields that change the page on their own](/learn/context-changes). A list that replaces itself on a timer is [auto-updating feeds that change while people read them](/learn/auto-updating-feeds). Screen readers and magnifiers differ in what they say and show when a window opens: test with the ones your users have.

---

Get this guide in your coding agent: MCP https://easeweb.dev/mcp (setup at the same address)
