Search topics
Pop-up windows that open as soon as a page loads
An online course site opens its spring offer in a new window as the My courses page loads, and the window takes focus from the page people asked for.
window.open('/offers/spring', 'offer', 'width=480,height=600'); The problem
People who allowed pop-ups for the site land in a window they didn't ask for, and screen reader, magnifier and keyboard users may not know that the page they opened is behind it
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.
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.
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.
4 of 10 groups affected
- No vision (affected)
- Low vision (affected)
- Colour vision (not affected)
- No hearing (not affected)
- Hard of hearing (not affected)
- No speech (not affected)
- Motor (affected)
- Reach, strength (not affected)
- Cognitive (affected)
- Seizures (not affected)
- Without vision A screen reader user follows the link to My courses and hears "Spring offer" instead: the new window has focus, and nothing says that the page they asked for is open behind it. Tab now moves through the offer, and the window has no page before it to go back to.
- Limited manipulation Keyboard and switch users find that Tab moves through the offer, not their courses. Getting back takes closing a window they never opened, or switching windows with a key such as Alt + Tab, and then finding their place on the page again.
- Limited vision A screen magnifier shows only part of the screen, so the small window can open outside the part in view. What they type and press now goes to a window they may not have seen open.
- Limited language, cognitive and learning abilities People who find it hard to keep track of where they are now have two windows from one site, and may not know which one holds their courses, or whether closing the offer closes the site too.
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.
Try it
Open My courses from the home page, then Tab to your first course
This browser allows pop-ups for the site, as its lessons need them. Follow the My courses link with the keyboard and watch where focus goes once the page has loaded; the panel under the window shows what a screen reader says. Close any window you didn’t ask for with its ×, then apply each fix and try again.
Broken Can you fix this?
The fix
Open a window only when people ask for it
<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>What is wrong3 points
- 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.
The offer on the page itself
<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>How it is fixed3 steps
- Delete the script. Nothing opens as the page loads, and focus stays on My courses, the page people asked for.
- 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.
- 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.
Why this fix: Change the page only when people ask
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.
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 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 covers when a new tab is worth keeping.
Verify the fix
4 checks, no mouse.
Test with: Keyboard, Screen reader, Zoom
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. A list that replaces itself on a timer is auto-updating feeds that change while people read them. Screen readers and magnifiers differ in what they say and show when a window opens: test with the ones your users have.
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.
References
- WCAG Understanding: change-on-request (opens in a new tab)
- WCAG Technique F52 (opens in a new tab)
- WCAG Technique F22 (opens in a new tab)
- WCAG Technique SCR24 (opens in a new tab)
- WCAG Technique H83 (opens in a new tab)
- developer.mozilla.org: open (opens in a new tab)
- support.google.com: 95472 (opens in a new tab)
EaseWeb service
Fixed it? Keep it from coming back.
I turn guides like this one into rules your coding agents follow and checks your CI runs. Then I retest by hand with a keyboard and screen readers, periodically.