Vanilla JS exit-intent code generator
What this does. It writes a small, zero-dependency script that shows an overlay when a desktop visitor moves the pointer out through the top of the page, after a minimum time, with a cooldown so the same person is not interrupted twice. You set the sensitivity, delay, cooldown and copy.
What it does not do. It does not detect mobile exits, collect email addresses, send analytics or style a finished campaign. The generated overlay has a heading, a paragraph, a button and a close button. You connect the button to your own form or link. Treat it as a starting point you test, not a drop-in conversion tool.
Exit intent is one of the few popup triggers that depends on a hardware assumption: a cursor. Touch devices have no pointer to leave, so any script that claims to detect a mobile exit is guessing from scroll direction or a back-button gesture. This generator is honest about that and only runs where a fine pointer exists.
The other assumption is time. Firing the moment a visitor lands is not exit intent; it is a page-load popup with a different name. The minimum-time field exists to make the trigger mean something: the visitor has had a chance to read, and the overlay arrives when they are leaving rather than when they arrive.
Build your snippet
Generated snippet
Paste it before the closing </body> tag, or load it from a file your site already serves. Nothing is sent anywhere: the code only runs in the visitor's browser.
How the snippet works
- It checks the input device. A media query for `hover: hover` and `pointer: fine` returns early on touch screens, so phones and tablets never see the overlay.
- It waits for the minimum time. The listener is attached immediately, but the handler returns until the delay has passed.
- It watches for a top-edge exit. The handler fires when the pointer leaves the document and its vertical position is within the sensitivity band.
- It applies the cooldown. A timestamp in localStorage stops the same browser from seeing the overlay again inside the window.
- It builds the overlay with DOM nodes. Your copy is inserted with `textContent`, not `innerHTML`, so an apostrophe in the headline cannot break the markup and injected HTML cannot run.
What to test before you ship
- Desktop, after the delay. Move the pointer up slowly; the overlay should appear. Move it up immediately after load and it should not.
- Touch device. Open the page on a phone. Nothing should fire, at any scroll position.
- Cooldown. Close the overlay, reload, and move up again. It should stay closed until the cooldown expires. Clear site data to reset while testing.
- Keyboard. The close button should be reachable by Tab and Escape should close the overlay.
- The real CTA. Replace the demo button with your form or link, then submit a test response and confirm it arrives where you expect.
- Iframes and builders. If the site runs your code inside an iframe, the pointer may never leave the parent document. Test on the published page, not the editor.
Limits worth knowing
Exit intent is a heuristic, not a signal. It fires on people switching tabs, reaching for a bookmark, or moving the mouse toward a second monitor. Some browsers fire the event differently, and a visitor who uses keyboard navigation may never trigger it. That is why the cooldown and minimum time matter more than the sensitivity setting.
The snippet also does nothing for mobile, where most traffic often is. If phones matter for your campaign, pair it with a separate timer, scroll or click popup rather than pretending one trigger covers both. The exit-intent guide covers the behaviour in more depth.
There is no analytics in the generated code. You will not know how many people saw it unless you add your own event tracking or use a builder that reports impressions and submissions.
Prefer a hosted popup instead of maintaining custom JavaScript? Open the exit-intent template in the studio. It includes the trigger, frequency rules, page targeting and a lead inbox, and it works on any site that allows a script. The no-limits page explains what the hosted version does and does not include.
Common questions
Does the generated exit-intent code work on mobile?
No. The snippet checks for a fine pointer and hover support, so it only runs on desktop devices with a mouse or trackpad. Touch devices have no cursor and no dependable leaving event. Use a timer, scroll or click trigger for phones instead.
What sensitivity should I use?
Start at 20 pixels from the top edge and test on a normal monitor. A higher value fires earlier and can interrupt people who only move toward a bookmark bar or tab strip. Lower it if the popup feels jumpy.
Why is the popup not appearing when I move the mouse up?
Check four things: the visitor is on a desktop with a pointer, the minimum time on page has passed, the cooldown has not already been set, and the code is not running inside an iframe that cannot detect pointer movement outside its own frame. Some browsers also need the pointer to leave the document, not just the viewport.
Does this snippet collect email addresses?
No. It creates a visual overlay with a heading, a paragraph, a call-to-action button and a close button. You replace the CTA with your own form or link. The snippet has no network calls and stores only a cooldown timestamp in localStorage.
Can I use the code without attribution?
Yes. The generated code is yours to use and modify, with no attribution required. It is provided as-is without warranty. Test it on your own site before relying on it.
Can I use this in WordPress, Shopify or Webflow?
Yes, where the platform allows custom JavaScript in the footer or theme code. WordPress needs a code-snippet plugin or child theme, Shopify needs theme code outside checkout, and Webflow needs a custom code embed. A builder that sandboxes code in an iframe may block exit detection.
Related tools and pages
- Popup copy generator — deterministic headline, subheadline and CTA combinations for four common goals.
- Popup ROI calculator — work out displays, signups, value and break-even from your own numbers.
- Exit-intent popup guide — why it is desktop only, how to test it and what to avoid.
- Exit-intent popup template — a full layout with copy and setup steps.
- Installation guide — placement, caching and CSP notes for a hosted popup.
Method and limitations
The generator runs entirely in your browser. It writes code from your inputs and does not send them anywhere. The snippet is provided as-is, without warranty, and was not tested on every browser or platform. No conversion rate, traffic or revenue claim is made: exit intent changes when a popup appears, not how people respond to the offer.
Written by Shailu016, founder of PopupLoom. Last updated 16 November 2026. Corrections: support@popuploom.com.