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.
Related
I'm working on a page that opens a modal window when the user clicks a certain radio button. I want to trigger whatever that event handler is via my own jQuery code. Right now, I'm attempting to mimic a user clicking on the radio button by:
$("#myRadioButton").trigger("click");
The code works somewhat. The state of the radio button does become selected. However, the modal window does not open.
What must I do to trigger the events and event handlers that make the modal window open?
(Also, is there a way in Chrome DevTools to see what events are attached to an element?)
This will make the click function work, with a id on the element. You will need to make some logic for the modal itself, inside the function.
Not sure there is a way to see the events in the developer console.
$( "#myRadioButton" ).click(function() {
//Whatever you wants to happen, when you click the button
alert( "You clicked on #myRadioButton" );
});
Try and check out -> https://jquerymodal.com/
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 want to skip the default pop up which will come on beforeunload event and want to show my own modal which is asking the user to give feedback on browser/tab close. In that modal if user click "OK" then I want to redirect the user to my feedback page and if the user clicks "NO" then the particular tab should close. Is there a way to do this?
As you can read here: https://developer.mozilla.org/en-US/docs/Web/Events/beforeunload you may change the event.returnValue of the beforeunload event to a custom string. Like this:
window.addEventListener("beforeunload", function( event ) {
event.returnValue = "Don't leave!";
});
This will open a confirm dialog when the user is leaving the current page.
You may open your modal window in this event, but this will not stop the user form leaving, so new content will not be seen.
Of course the unload event can not be canceled (https://developer.mozilla.org/en-US/docs/Web/Events/unload) and UI interactions are ineffective (window.open, alert, confirm etc.)
So i think the closest you can get it this: http://jsfiddle.net/s6qWr/
var $modal = document.getElementById("modal");
window.addEventListener("beforeunload", function(event){
$modal.classList.add("visible");
event.returnValue = "Please tell us about your experience";
});
I have got a primefaces button with an onclick that calls a function with this in it:
popup = window.open(urlToOpen, windowName, params);
if (!popup.opener) {
popup.opener = self;
}
popup.focus();
And then the popup shows but as soon as I hover(I'm not clicking!) over any primefaces button in the parent window the popup loses focus.
Does anyone have any idea why this problem might occur?
Check if some button or html element have mouseover callback with focus() in it.
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>