How do I find a child window when the parent is refreshed? - javascript

hejdig.
In a web solution I want to reuse my child window but lose the reference to it when the main window refreshes.
How can I find an orphaned child window? (which is orphaned due to parent refresh)
/OF
Situation:
Parent window exists.
User presses button to open Child window.
User enters text in Child window.
User asks Parent window to refresh.
User presses button to open Child window.
Child window refreshes and user's text is gone.
In my case the Parent is a CMS and it is quite natural for it to reload when the user looks at a new article; this situation isn't new. What is new is that I have an editable child window.
So the real-world situation is like:
User browses a site (a CMS).
User opens a popup and is asked to enter some data.
User enters some data in the popup.
User decides to look at a new article (gets a new URL in parent).
The popup is now hidden so the user clicks top open the popup again.
The popup is refreshed (what I try to avoid) and focused.
The only workarounds I have found is to use iframe, frameset or open a third window and none of these solutions are possible in my situation.
Calling
wnd = window.open( "", "uniquename" );
doesn't work since it reloads the child.
Untried ideas are to check if the wnd handle is unique for the browser session and store it in a cookie or similar. Another untried idea is if the child can find out if it is orphaned and then, through a timer, try to find its parent.

hi as you said yourself try putting timer in child which will registeritself to prent
so in parent create function
var wnd = null;
function registerChild(child){wnd = child}
and in child in timer every second or half
window.opener.registerChild(window);

Related

Getting Child window reference from parent after parent is refreshed

Here is the scenario:
I'm in parent window. I click on a link, which opens a child window
Now I'm in child window, I enter some data and click on a submit button
Now, the child window refreshes. After the child window completes refreshing, the parent window refreshes.
After the parent window refreshes, the child window goes background, which I don't want. I want that to remain foreground.
NOW, I searched how to get the reference of child window from the parent window and found this link-
http://www.codeproject.com/Articles/25388/Accessing-parent-window-from-child-window-or-vice#b
My question is - Will I be able to successfully get the reference of the child window even after the parent window has refreshed?
More info: This happens only in IE and not in Chrome/Firefox.
UPDATE: As per this link - https://www.daniweb.com/programming/web-development/threads/48485/parentchild-windows-references
The parent will not have control over child anymore. But is there a way I can maintain the focus on the child window even after the parent window refreshes?

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 can I get number of child windows for a browser

I have one icon (say open) in home page. When I click on this icon one child window will be open and the icon in that home page is also changed to 'close icon'. When close this popup window the icon should be same as previous icon (i.e. open icon) in home page. It's working fine when I stay on the same page.
But when redirecting from home page to next page the entire page gets reloaded. And the default image (open icon) is displaying even if the popup window is opened.
Now my requirement is:
At the time of page redirection the image should be loaded based upon the popup window. i.e. if popup window is open it should display the close icon otherwise it display open icon.
If page is refreshed or redirecting to another page the reference of the popup window is removed. then how can I get the reference of that popup window in a redirecting page.
How to count the number of child windows for a browser
EDIT:
I have tried the following solutions:
I set cookie at the time of opening a popup window and reset that cookie whenever I have closed that popup window. But the problem is, at the time of page redirection if I close the popup window the cookie is not reset to it's previous value, because the page is still in processing.
same problem with the session variable also
Please help me.
Set a cookie or a session variable when you open and close. This way you can remember the state of your popup window during new requests
When you go from one page to the next, you lose the reference to the pop-up window. But the pop-up window doesn't lose its reference to the main window. window.opener will always point to the window that opened it, even when there's a page change. Use this fact to reestablish communication between the windows after a navigation event. You might need to use an interval function to probe the main window, as I don't think you can listen for an event.

Help with accessing a pre-existing window AFTER opener is refreshed!

Alright, I'm at my wit's end on this issue.
First, backstory. I'm working on a video management system where we're allowing users, when adding new content, to upload and, optionally, transcode a media file. We're using Java applet for the browser-based FTP client.
What I want to do is allow a user to initiate an upload and then send the FTP connection instance to a popup window. This window will act as a job queue for the FTP transfer process. This will allow users to move about the main interface without having to stay on the original page until an individual file transfer is complete.
For the most part I have all of this working, but here's a problem. If the window is closed, all connections are dropped and the upload process for all queued files will be canceled.
So, if Window One opens the Popup Window, adds stuff to the queue, refreshes the screen or moves to a different page, how will I access the Popup Window?
The popup window and its contents must remain persistent while the user navigates through the original window. The original window must be able to access the popup to add a new job to the queue. The popup window itself is independent of the opening window, so communication only happens in one direction:
Parent -> Popup
Not
Parent <- Popup
Window.open(null, 'WINDOW_NAME'); will not work in this case. I need to check if a window exists BEFORE using window.open.
Help!?!?
SOLVED!!!
Here's what I did. In the popup window, I added an arbitrary variable. The parent window checks for the existence of this variable. If it's defined, then the window must be open. If not, then open a new window.
The way this works is I just use window.open(null, 'WINDOW_NAME') to open a very tiny browser window. If you don't specify a URL, it will either:
A) Open a blank window
B) Focus the existing window
It then checks for the variable. If it doesn't exist, it closes the window and returns 'false'. If it does, it focuses the existing window and returns 'true'.
function isWindowOpen(targetWindowName)
{
tempTargetWindow = window.open('', targetWindowName, 'width=1,height=1');
if(typeof(tempTargetWindow.thisWindowExists) == 'undefined')
{
tempTargetWindow.close();
return false;
}
return true;
}

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