I need to open a popup window, which when closed, opens a new pop up window. Then when you close that one another opens.
I'm aware that this functionality can have uses for spam and nag-ware, but I need it for a user experience survey. Don't ask me, it wasn't my idea.
How do you do this?
The Javascript in the popup window can access the original window using the opener property.
Handle the onbeforeunload event in each popup window and call a function in the parent window to continue processing (and open the next window).
For example:
(In the original window)
window.onPopupClose = function(popupName) { /* ... */ };
(In each popup window)
<body onbeforeunload="opener.onPopupClose('someName');}> ... </body>
The popupName parameter is just an example, you can do whatever you want (such as having three different functions).
Popup the first window have an onclose event in the first window that pops-up the second and an onclose event in the second that pops-up first. Have some sort of button on both pages that removes the onclose event so you can escape from it too.
Try :
<body onbeforeunload="javascript:window.open('Default.aspx','nsf','menubar=1,resizable=1,width=350,height=250');">
</body>
Related
I have two browser windows open, let's call them parent and popup. When the user finishes his work on the popup window I want him to click on a button that will call a function on the parent window, and close the popup window. My problem is that popup is being opened until the called function on parent won't finish. This is annoying because the function on parent opens up alert, confirm etc boxes, and the popup window is still in the foreground. So I want to run the function call and window closing simultaneously.
Here is the code:
window.opener.addStationery(id, name, qty);
this.close();
Invert those lines:
this.close();
window.opener.addStationery(id, name, qty);
Even closing the window the scope is still on.
Close the Popup in the parent function in the parent page before doing other operations.
I'm doing some selenium web testing and on this one site I'm automating a modal popup would sometimes show up randomly and would prevent me from grabbing other elements. I know there are built in Selenium methods for closing the popup like alert().dismiss() but this would mean I know when the popup would show up and I don't it shows up at random.
I would like to know how to attach an event listener for when these modal popups show up and have a callback that would close out of it. please and thanks
If you know where is the code that triggers the popup, you can simply inject few line of javascript in webdriver and nullify the popup.
As an example, if the popup appears after a couple of seconds and is triggered by the following code:
setTimeout(function () {
showModal()
}, 5000);
you could override the modal function in the webpage with the following (Java) code:
driver.executeScript("showModal = function () {}");
the next time the modal is executed this will trigger an empty function.
In my application, when the session gets time out a modal window asking for a password gets dispalyed. When I click the submit button, the event doesn't get fired and It again triggers the session call.The screen gets properly redirected but the thing is I can't invoke any javascript function from the modal window. What will be the problem?
most likely due to the fact that when you dynamically add an element you have to assign click event like this:
$("h2").on('click', 'p.test', function() {
alert('you clicked a p.test element');
});
Need to see your code but its what i ran into a while back. good luck.
I am writing an Ext JS 5 application and seem to be losing a reference to a child window that I am opening.
The following opens a new window to w3schools, as a sample. Later, when I close the window, the beforeunload event DOES NOT fire.
this.chatPopOutWindow = window
.open(
'http://www.w3schools.com',
'chatPopOutWindow',
'width=380,height=400,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no');
Ext.get(me.chatPopOutWindow).on('beforeunload', function() {
.....more code
In this code sample with a bad url (the new window opens to a 404 error), when I close the window the beforeunload event DOES fire:
this.chatPopOutWindow = window
.open(
'/someBadURL',
'chatPopOutWindow',
'width=380,height=400,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no');
Ext.get(me.chatPopOutWindow).on('beforeunload', function() {
.....more code
Why does the beforeunload event not get triggered in the first scenario?
I should have specified that the window I want to open is not cross-domain; it is in the same domain (though not in the example above).
Anyway, I found the answer. Apparently, Ext JS 5's Ext.get(me.chatPopOutWindow).on('beforeunload', function() {... is not reliable. Instead, use me.chatPopOutWindow.onbeforeunload = function() {..., which is the JavaScript syntax for listening for a beforeunload event..
I have a parent window and when I click a link from parent window, the link opens in a new window. I need to show confirm message on close of child window.(i.e. the opened link )
childWindow = window.open("http://www.google.com","width=400, height=400");
I like confirm close for child window. like
childWindow.close(function(){var confirmClose=confirm("Are you sure to close ?");
});
If the user clicks "OK" of the confirm box then the child window will be closed, else if the user click "Cancel" then the child window will not be closed
Use onbeforeunload event: https://developer.mozilla.org/en/DOM/window.onbeforeunload
To set up a confirm dialogue, add a listener to the beforeunload event of the (child)window as demonstrated in Confirm message on browser page close and prevent the action eventually.
If you call childWindow.close(), the window will get closed instead of hooking a callback function.