how to refresh parent from child window in php - javascript

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();
}

Related

Close the window when Chrome print dialog is clicked

I want to close the current tab in Chrome when the print button in Print Dialog is clicked by the user. I tried with window.print() and setTimeout(), but this will close the dialog even if the print is canceled by the CANCEL button.
Is there is any solution for this?
This is what I have done so far:
function printThis(){
window.print();
setTimeout(function(){
window.close();
},5000);
}
You can call the this method in onload, once this print dialog is dismissed the alert prompt will automatically be called and ask the user whether print or not if print has been done, the user will be automatically redirected to the page.
If you want to close the window you should open the particular window by window.open method, you cannot close the window by just opening by URL or redirects.
Example:
window.open("https://yourside.com", "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400");
Then you can call window.close in the window which is opened by window.open.
window.onload = function () {
window.print();
setTimeout(function(){ if(confirm("Have you printed ?")) { window.location.href="/your_page"; } }, 1);
}
please use this code.
window.addEventListener("beforeprint", function(event) { ... });
//or
window.onbeforeprint = function(event) { ... };
window.onbeforeprint will be called when press Ctrl+p or else for opening print dialog
e.g
window.addEventListener("beforeprint",
function(event) {
window.close();
});
or if you want to close window after print button pressed, please use window.onafterprint like this
window.onafterprint = function(){
window.close()
}
You can use onafterprint event:
window.onafterprint = function(){ window.close() }
Very simple!
on print page (In my case it is "print-page.html") use this script -
<script>
window.onafterprint = function(){
window.close()
}
</script>
It will close the new tab when the user clicked the print/cancel button! Tested on chrome and works fine.
Make sure you have already called the print interface using this method -
<input type="button" value="button name" onclick="window.open('print-page.html','popUpWindow','height=687,width=1057,left=10,top=10,scrollbars=yes,menubar=no'); return false;" />
Best of luck!

how to call function on window close in angular 2

oauthLogin(app) {
this.openAuthPopup(
'/assets/auth.html?socialApp=' + app, () => {
if (this.SharedService.getAuthorization()) {
this.checkRegistrationStatus();
this.SharedService.changeLoggedInStatus(true);
this.SharedService.changedisplayName(this.SharedService.getDispalyName());
this.router.navigate(['home/dashboard']);
}
}
);
}
my popup window opening code
openAuthPopup(url, callback) {
window.open(url, '_blank');
callback();
}
i have created this function and calling this function from html. This function is opening a popup tab. I want such that my if condition to be checked as my popup tab get closed, but currently what is happening is like my if condition is checked during the processes on popup tab.
I am stucked. Help needed.
thanks in advance
I think you need to listen to the event beforeunload with HostListener from Angular
#HostListener('window:beforeunload', ['$event'])
beforeunloadHandler(event) {
// actions
}

How to close specific pop-up window in asp.net using javascript?

Is it possible to close specific pop-up window when other page is clicked using javascript? Something like below...
function closePopUp()
{
window.close('popup.aspx');
}
Thanks in advance.
if you open a pop with a name then it is possible
var popUp;
function OpenPopUp() {
//popUp is the name of the window
popUp = window.open("Yourpage", "something", "width=550,height=170");
}
Then you can close it as follows
function closeit() {
//closing a popup with name popUp
popUp.close();
}
OnClientClick="javascript:window.close()"

Auto refresh parent window after closing popup

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();

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