JS window.close popup isn't working after refresh of parent - javascript

Currently i'm creating a simple html/php/js project for internal use and found a little problem i can't solve by my self :-(
In my parent window is a JS function which opens and closes a popup with:
function openit(){
boersenfenster = window.open('boerse.php','_blank','scrollbars=no');
}
function closeit(){
boersenfenster.close();
}
Now after a while the parent window refreshes to get fresh data of a csv file and after the page reload the closeit() function isn't working anymore. In my thoughts, the parent window can't remember the openend popup after the refresh but how can i fix this problem?

Yes, I believe the parent window has lost the the link, so you can either
use ajax to update your page, or close the child window like this
window.addEventListener('beforeunload',function(e){
boersenfenster.close();
};
and then reopen the child window after the page has reloaded

Related

How to focus the parent page from child window in Firefox?

I am calling the parent page javascript function from child window with code below, which displays some alert message on parent page and closes the child window.
window.opener.CallAlert("test is"+test);
opener.focus();
self.close();
What is happening with above code snippet is alert comes on parent window but focus remains on child window. i need explicitly go to parent window. Once I click ok on alert child window closes.
Everything is fine but I want the to focus on parent window once i call the window.opener.CallAlert() from child window.
Edit
Looks like opener.focus(); works on IE but not mozilla. Any workaround for firefox?
It would appear that this is not guaranteed to work and is at the discretion of the browser.
See this thread: window.opener.focus() doesn't work
just try the obvious:
window.opener.focus();
try with delay setTimeout(function(){self.close()},300) and then display alert on parent page. It will schedule to close the current window after some delay automatically with display of alert message on parent signal

How to close all the child pages on LogOut

We have a Master page and some child pages.One in them is popup by window.open function.The problem occurs When logout is clicked at Master Page.whole System is redirect to Login page except that Popup window.when i clicked on that child-page then it will redirected to Login Page.We need it be closed directly after logout is pressed.
Is there any script to close window if the window's location is known.I want to close that child page in Logout click.
like window.close('Authentication.aspx');
please tell me if it is possible
Thanks ,
Rakesh.
If you've opened a popup window using the following code, with a presumed name of "popupwindow"...
window.open("myurl.html", "popupwindow", "height, etc");
Then in your login page try the following javascript
if(window.name=="popupwindow"){
window.close();
}
UPDATE based on comments by OP...
If you no longer have a reference to the window (because the parent window has refreshed for example), then I believe it is almost impossible to detect whether a popup window with a particular name exists or not.
I say "almost impossible" because one option in this situation is to try opening the window again giving a blank URL. If the window already exists, then the window will remain on the same page as before, but now you have a reference to it, and can close as necessary.
var myWin = window.open("","popupwindow");
myWin.close();
However, the downside to this is that if the window does not exist, the user will see a blank window open before then being closed - so not a nice user-experience.

how to redirect a page which creates a popup, from that created popup using jQuery?

I am new to jQuery. I have a button on main page of my web application which creates a login pop. If user enters correct password then popup should be disappeared and the page which create that popup should go to welcome page of that user. I know how to disappear the popup if user enters correct password. How can I tell the explorer window which created that popup to go to the welcome page? Thanks in advance.
I believe with Javascript you can redirect the parent window with:
window.opener.location.href = <your url>;
And then simply close your popup:
window.close();
You don't need jQuery for this. Some simple JavaScript should do the trick.
//reload the parent window
//window.opener.location.reload();
//to change the parent window location
window.opener.location.href = "welcome.htm";
//close the current window
self.close();

How to handle closing of a previously opened window

I have a form where the user fills out stuff. Towards the end they click on a link which opens up a new window to record a video. Once they are done recording they close the window.
How can I react to the closing of the window on the first window form? I may want to submit the form automatically or have an ajax request started to display info etc... If this isn't possible what do you suggest?
Edit:
Parent window:
function someAlert() {
alert("success");
}
Child window:
window.onunload =window.opener.someAlert();
If you opened it with window.open, you can call
window.opener.someJavaScriptFunctionInParent();
call it with window.onunload or right before window.close()

What's different when a page is opened by window.showModalDialog?

Anyone knows the difference?
The problem I met is that the page stops working correctly when opened by window.showModalDialog
window.showModalDialog vs window.open
Window.open will open up a new window through Javascript, with the URL and other features of the window that u pass as parameters. Here the parent window which opens the new window and the child window are independent windows.
Eg. Below
`window.open('winOpen.htm','name','height=255,width=250,toolbar=no,directories=no,status=no,
linemenubar=no,scrollbars=no,resizable=no');`
Window.showModalDialogue again works smilar to a window.open only diffrence being its a Modal window, It opens up as a new window but doesnt allow the user to access the parent window, unless you explicitly close it.
Here the child window is dependent on the parent window. If you close the parent window the child would also get closed.
window.showModalDialog("xpopupex.htm","name","dialogWidth:255px;dialogHeight:250px");
ShowModalDialogue windows can be used when u want the user to perform a particular action in the new window before he access the parent window again. like login before he can access the parent page..
tryed to make it as simple as possible...hope this help.. ;)

Categories