Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8559965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:10:21+00:00 2026-06-11T16:10:21+00:00

I’m trying to launch a popup from certain pages. I want users to see

  • 0

I’m trying to launch a popup from certain pages. I want users to see the popup only when:

a) they close the browser tab
b) they hit the browser’s Back button
c) they go to a page other than the next step in the purchase path – basically, when they go to any URL that does not contain the string “/checkout/”.

I’ve looked at popup examples that load body onUnload, and that’s a bit too global. I just want a popup – a true actual popup – to launch if they try to leave the checkout path.

I’ve looked at several questions on StackOverflow, but none of them quite seem to answer my question. The onBeforeUnload mentioned in this answer https://stackoverflow.com/a/3753963/1634459 might work…MIGHT…but I’m not totally sure how to implement it with the conditions I listed above.

…help?

Here’s the popup window code I’d like to use:

<script language="javascript" type="text/javascript">
var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="center"){LeftPosition=(screen.availWidth)?(screen.availWidth-w)/2:50;TopPosition=(screen.availHeight)?(screen.availHeight-h)/2:50;}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);
if(win.focus){win.focus();}}
function CloseNewWin(){if(win!=null && win.open)win.close()}
window.onfocus=CloseNewWin;
</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:10:22+00:00Added an answer on June 11, 2026 at 4:10 pm

    Here you go; I wrote this for the marketing team at a previous job. You should be able to adapt it pretty easily; just update the URL and params as appropriate.

    This code will open a popup when the user leaves the page, unless they leave by submitting the checkout form. (If you have more than one form on the page, which you shouldn’t in a checkout flow, you will need to fix that as well.)

    var nag = function () {
    
        return {
            // assume the user is going to leave, get ready to pounce!
            doWant: true,
    
            // FALCON PUNCH
            deploy: function () {
                if (nag.doWant) {
    
                    var width = 449;
                    var height = 298;
    
                    args = "width=" + width + ",";
                    args += "height=" + height + ",";
                    args += "location=0" + ","
                    args += "menubar=0" + ","
                    args += "resizable=1" + ","
                    args += "scrollbars=0" + ","
                    args += "status=0" + ","
                    args += "titlebar=0" + ","
                    args += "toolbar=0" + ","
                    args += "hotkeys=0"
    
                    var demo_window = window.open("YOUR_URL", "main", args);
    
                    try {
                        demo_window.focus();
                    } catch (err3) { };
                }
            },
    
            // oh, off to step 2? that's cool. carry on.
            ignore: function () {
                nag.doWant = false;
            }
        }
    } ();
    
    window.onunload = nag.deploy;
    document.forms[0].onsubmit = nag.ignore;
    

    If you want to be able to STOP the user from leaving the page, I can help you with that update.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I want use html5's new tag to play a wav file (currently only supported
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to render a haml file in a javascript response like so:
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.