Refresh a specific page when pop-up is closed (jQuery) - javascript

I have a pop-up called PopUp1 (page0.aspx). When the user clicks a row in PopUp1's GridView, it opens a new pop-up that loads my page1.aspx.
If the user clicks a link in the new pop-up (page1.aspx), then the content will be replaced with that of page2.aspx.
What I want: If the user closes the window of my second pop-up that opens page1.aspx or page2.aspx, then refresh PopUp1 (page0.aspx).
How can I do that via jQuery ?

in page1.aspx and page2.aspx add some javascript to refresh their parent (you don't need any jquery for this)
In your markup:
<body onunload="refreshParent();">
In your javascript:
var refreshParent = function () {
if (opener && !opener.closed) {
opener.location.reload();
}
};
Edit: alternatively, if you want to keep your logic seperated from your markup:
$(window).unload(refreshParent);

In your new popup (page1.aspx or page2.aspx), put the following jQuery and it should refresh the opening window when that popup is closed or refreshed:
$(window).unload(function(){
window.opener.location.reload();
});
If you'd like you could also change the location of the opening page by using the .assign method if you want to do some kind of workflow logic in your page,
for example window.opener.location.assign('http://newurl');

You could use plain javascript
window.opener.reload();

Related

How to refresh the one browser window from another?

I am creating an application in which
There is datalist for items which contains collapsible panels with edit and delete button in the header panel.
On click of edit button I opened a new browser window for edit details using window.open(); javascript, which contains item details of the respective item and save button.
So I need functionality like when user clicks on save button on edit window, edit window should get closed and the parent page which has datalist should get refreshed. Note: Please consider I have URL of parent page.
For Closing the window I have tried following code:
string closeScript = "<script type='text/javascript' language='javascript'>window.close();</script>";
ClientScript.RegisterClientScriptBlock(typeof(CmsManagementPage),
"cancelScript",
closeScript);
But the edit window is not closed, and is there any solution for refreshing the parent page?
You can create the following function in javascript and call on edit button:
function editClose(url) {
window.opener.location=url;
window.close();
}

New window/tab can't be closed via script within the new window/tab

I have 2 pages. One is the main page, and one is a form page. When I click a button on the main page I want the form to popup as a new tab/window and when the user is done they can click a "close" button on the new Form page to close the window and return to the main page.
I am opening a new window with the following javascript:
// This javascript is on the MAIN page
window.open("http://www.baseurl.com/form", "UserForm");
I have a "close" button on the poppup that I want to use to close the new window and return to my Mian page. Like this:
// This javascript is on the FORM page
$(document).on("click", "a#close_form", function(event){
event.preventDefault();
window.close;
}
The close button won't work even though the form page was opened with Javascript.
What am I doing wrong?
close is a method - you need to call it by adding () to the end.
$(document).on("click", "a#close_form", function(event){
event.preventDefault();
window.close(); // < added brackets to call the function
}
Your current code was simply getting the reference to the function and not executing it.

how to show a message in popup at a page when a user come to that page but the condition is we have to use Featherlight popup no Colorbox or etc

Please visit at this url, there is a 'default' button when you click on this url a popup will appear.
I want the same but when i don't want to fire any user event this popup will appear onload
http://noelboss.github.io/featherlight/
If you want the popup on page load then just add some JS code:
$(document).ready(function() {
$("#popup").click();
});
give the id or class name of your tag where is popup exit instead of popup object.

JQuery-bPopup Remove the old page from the popup and load a new page in same

In JQuery bPopup, how can i remove the old page from the popup and load a new page in same popup without closing it?
I have tried following 3 things, but still no success:
Applied anchor tag in child page, but it opens the new page in parent page
Applied $('.popup_content').bPopup({...}); in child page, it opens new page along with the previous page, both page are there in two rows.
Put 4 divs for popup in parent page, and called bPopup() for seperate popup divs in child pages. It works well, but keeps open the overlay of the old page.
Try this function:
function fnPopupClose1() {
var popup = $('.popup1').bPopup();
popup.dispose = true;
popup.close();
}

Parent Jsp page refresh when click on popupwindow alert box

I am working on jsp's, I have two jsp one in configDb.jsp, in that I have written code to retrieve the values from database and display it. In this whereas I have option like newconnection.. its a popup window. When I click on that it opens popupwindow and taken the values and store them in a database, but in my parent page I am not able to display those values. After I click on the ok button in popup window, I have to refresh the parent page, then I am able to see the values which I have created few seconds back by the new connection page. Could anyone please help me out?
You can include this in your HTML for the popup window.
<script type="text/javascript">
function proceed(){
opener.location.reload(true);
self.close();
}
</script>
<form onsubmit="proceed()">
...
</form>
Actually you can obtain the answer by googling "javascript refresh parent page from popup" and you will see stackoverflow's answer :)
A better alternative without the need of refreshing the parent page can be achieved by adding a submit button listener and perform a DOM action to insert the new element with new content. This can be easily done by Javascript.

Categories

Resources