Devone

How Can You Instantly Open a Pop-Up Window Right After You Close One?

Asked by Devone 2 years ago pop-up window


Neil Monroe
0
 
You could add an event function to your popup close action and execute this when the first window is closed. It could even be passed into the popup open function as a function reference so that you could configure a different action on each call to the popup open function.

To do as above, you'd probably need to create a JavaScript "class" for the popup window object so that you can store the variable for the close function in a separate scope and use it for as many windows as you need independently.

//---------------------------------------------------

// Define the Popup "class"
//---------------------------------------------------

function emptyFn() {};

function Popop() {
    this.onclose = emptyFn;
}

Popup.prototype.open = function(onclose) {
    this.onclose = onclose;
    // Do the rest of your window open code here...
};

Popup.prototype.close = function() {
    // Do your window close code here...
    If (typeof this.onclose == "function") this.onclose();
};

//---------------------------------------------------

// Now create an instance
//---------------------------------------------------
var myPopup = new Popup();
myPopup.open(function() {
    var anotherPopup = new Popup();

    anotherPopup.open(); // No additional popup onclose for this one,
but you could.

});

by Neil Monroe 2 years ago

Answer this question

How Can You Instantly Open a Pop-Up Window Right After You Close One?

0 errors found:

 
0