Skip to content
easeweb
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.

WCAG 2.2
SC 3.2.5AAA
Required by
Not required by Section 508 or EN 301 549
Broken window.open('/offers/spring', 'offer', 'width=480,height=600');
The accessibility problem illustrated: No vision:Where did my courses go?
01

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

02

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?

BrokenA script that opens the offer as the page loads

Welcome back

Pick up where you left off.

My courses

A recreated demo. The broken version is intentionally inaccessible.

03

The fix

Open a window only when people ask for it

Before
BrokenA script that opens the offer as the page loads
<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.
After

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

04

Verify the fix

4 checks, no mouse.

Test with: Keyboard, Screen reader, Zoom

0 of 4 checked

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.

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.

See the service