Auto refresh parent window after closing popup - javascript

I am having 2 pop up screens in my (Main) jsp.
In the first pop-up the user will update the required information(Update) and after submitting the info, a new pop up will be shown that shows the modifications(View).
I would like to refresh the Main page when the user clicks on the close "X" in the view page.
I tried to use some scripts like the following in the view page, but it did not work:
<script language="JavaScript">
function refreshParent() {
window.opener.location.href = window.opener.location.href;
if (window.opener.progressWindow)
{
window.opener.progressWindow.close()
}
window.close();
}
</script>

Try putting this javascript code in your popup window:
window.onunload = function(){
window.opener.location.reload();
};

function ref_and_close()
{
opener.location.reload();
self.close();
}
//just call the function
ref_and_close();

Related

how to refresh parent from child window in php

I had opened a popup window from a modal now I need to refresh the page where my modal is by closing popup window or by a close button i had tried writing some codes i found here but not working some of my codes are
//this is not working
function closeAndRefresh(){
opener.location.reload();
window.close();
}
Call below function on onClose popup/onclick close button
function closeAndRefresh() {
location.reload();
}
function closeAndRefresh() {
window.top.location.reload();
}

Close current browser in other page

I have the below HTML, which redirects the page and closes the current window
<a href="http://www.google.com" onclick="close_window()">
I tested it, it can redirect page OR close window only, but cannot do both at the same time, that means after redirecting to another page, it does not close the window. Could you advise how to make it close the window after redirect?
You will need Javascript to do this. Use window.close():
close();
Note: the current window is implied. This is equivalent:
window.close();
or you can specify a different window.
So:
function close_window() {
if (confirm("Close Window?")) {
close();
}
}
with HTML:
close
or:
close
You return false here to prevent the default behavior for the event. Otherwise the browser will attempt to go to that URL (which it obviously isn't).
Now the options on the window.confirm() dialog box will be OK and Cancel (not Yes and No). If you really want Yes and No you'll need to create some kind of modal Javascript dialog box.
you have to try window.open for this:
<html>
<head></head>
<body>
<script type="text/javascript">
function test(){
testWindow = window.open("http://www.google.com");
setTimeout(function() { testWindow.close() },5000);
}
test();
</script>
</body>
</html>

pop up window not closing after the parent window is reload

In my parent jsp page I've used:
function popUpClosed() {
window.location.reload();
}
And in child (popup window) I've used:
<script type="text/javascript">
window.onunload = function() {
if (window.opener && !window.opener.closed) {
window.opener.popUpClosed();
}
};
</script>
by this code, parent window is reloading after inserting data from popup window but popup window is not closing, I've to manually close the popup window. How can the popup window be made self close??
To close the window in your popup change the code like this:
<script type="text/javascript">
window.onunload = function() {
if (window.opener && !window.opener.closed) {
window.opener.popUpClosed();
}
window.close();
};
</script>
Refer here: How to close the current window.
onunload is called whenever your page unloads.
If you are posting data, by a submit button, you are unloading the document.
This is not the same as closing the windows.
If you want to capture only the close of the window, you should use something like:
window.onbeforeunload = windowExit;
function windowExit(){
//do somethng
//check that you are not submitting.
}
Here are two sample functions that open and close a popup window. If you create your window within a variable, you can then target the window you've opened, meaning you can close it.
<script>
function openWin()
{
myWindow=window.open("","","width=200,height=100");
myWindow.document.write("<p>This is 'myWindow'</p>");
}
function closeWin()
{
myWindow.close();
}
</script>

retain popup window when navigating website

The following code produces a javascript popup when a page is loaded and then closes the popup window when the parent window is closed.
<script language="JavaScript">
var player;
function load() {
player = window.open('http://www.google.com','player','height=320,width=320,scrollbars,resizable');
}
function unload() {
player.close();
}
window.onload = load;
window.onunload = unload;
</script>
This is working fine, however it closes the popup window when switching pages on the site. Is there any way this can be altered to keep the popup window until the actual URL/Site window is closed?
I think you have to check the status of the parent window from the child, instead of vice-versa.
This code has not been tested, but I'm taking a stab at the concept:
window.opener.onunload =
setTimeout(
function(){
if (!window.opener) self.close();
}, 1000);
Short answer is NO, the only way to hook into the event that closes the window is onunload, which fires when the document is unloaded (like when you navigate to another page).
Maybe you could check window.opener on the popup (with a timer, or onfocus), to check if the window that originated the popup still exists, then close the popup if it doesn't.
This may help you:
<script language="Javascript">
var player;
function load() {
player = window.open('http://www.google.com','player','height=320,width=320,scrollbars,resizable');
}
function unload() {
if (!(window.location.equals('http://yourSiteName.com'))) {
player.close();
}
}
window.onload = load();
window.onunload = unload();
</script>

need to refresh web page after clicking close on pop-up window

I have a pop-up window a user logs into, once they are logged in successful, I have a message that has a link to close the window. But I want it to not only close that pop up window, but I want it to refresh the webpage the pop-up window was clicked on.
So the page can refresh to see that there is a valid login session for that user.
Is this possible w/ jQuery?
In your popup window:
$('#closeButton').click(function(e) {
window.opener.location.reload(true);
window.close();
e.preventDefault();
});
Reloads the parent page and closes the popup.
You can do this:
window.location.reload()
It just tells javascript to reload the page, this is not dependent on jQuery.
onclick="javascript:window.opener.location.reload(true);self.close();"
Here is a code that refresh parent window and closes the popup in one operation.
<script language="JavaScript">
<!--
function refreshParent() {
window.opener.location.href = window.opener.location.href;
if (window.opener.progressWindow) {
window.opener.progressWindow.close()
}
window.close();
}
//-->
</script>
Use this code in ajaxlogin.js file for mvc 4 user
$('#closeButton').click(function(e) {
window.opener.location.reload(true);
window.close();
e.preventDefault();
});
Its working fine
Works efficiently for me:
$(window).unload(function() {
if (!window.opener.closed) {
window.opener.__doPostBack('', '');
e.preventDefault();
}
});
Use this code in window close event like
$('#close').click(function(e) {
window.opener.location.reload();
window.close();
self.close();
});
http://www.delhincrjob.com/blog/how-to-close-popup-window-and-refresh-parent-window-in-jquery/

Categories