parent window open child window - javascript

I want a page that open child window. The child window will be redirect to other website for processing. The other website will send the result to our server by redirect on the child window.our server will process the result and return to parent window and close the child window. Can it be done and how?

You use window.open method to open a child window and store the returned reference to interact with it later.
You use the window.parent property from the child window to access the parent window.
Here is an article demonstrating the approach.

Related

Reload parent window when parent window changes

I want to refresh the parent window after closing the pop up window.
I have used
window.opener.location.reload();
This works fine in one case when the parent window is the calling window. But there is another scenario where we set the parent of the calling window as another window.
So instead of loading the calling parent window it loads the other page. Can we set a fixed parent window as in my case its obviously changing due to some business rules.

When to use window.opener / window.parent / window.top

In JavaScript when to use window.opener / window.parent / window.top ?
window.opener refers to the window that called window.open( ... ) to open the window from which it's called
window.parent refers to the parent of a window in a <frame> or <iframe>
window.top refers to the top-most window from a window nested in one or more layers of <iframe> sub-windows
Those will be null (or maybe undefined) when they're not relevant to the referring window's situation. ("Referring window" means the window in whose context the JavaScript code is run.)
I think you need to add some context to your question. However, basic information about these things can be found here:
window.opener
https://developer.mozilla.org/en-US/docs/Web/API/Window.opener
I've used window.opener mostly when opening a new window that acted as a dialog which required user input, and needed to pass information back to the main window. However this is restricted by origin policy, so you need to ensure both the content from the dialog and the opener window are loaded from the same origin.
window.parent
https://developer.mozilla.org/en-US/docs/Web/API/Window.parent
I've used this mostly when working with IFrames that need to communicate with the window object that contains them.
window.top
https://developer.mozilla.org/en-US/docs/Web/API/Window.top
This is useful for ensuring you are interacting with the top level browser window. You can use it for preventing another site from iframing your website, among other things.
If you add some more detail to your question, I can supply other more relevant examples.
UPDATE:
There are a few ways you can handle your situation.
You have the following structure:
Main Window
Dialog 1
Dialog 2 Opened By Dialog 1
When Dialog 1 runs the code to open Dialog 2, after creating Dialog 2, have dialog 1 set a property on Dialog 2 that references the Dialog1 opener.
So if "childwindow" is you variable for the dialog 2 window object, and "window" is the variable for the Dialog 1 window object. After opening dialog 2, but before closing dialog 1 make an assignment similar to this:
childwindow.appMainWindow = window.opener
After making the assignment above, close dialog 1.
Then from the code running inside dialog2, you should be able to use
window.appMainWindow to reference the main window, window object.
Hope this helps.
top, parent, opener (as well as window, self, and iframe) are all window objects.
window.opener -> returns the window that opens or launches the current popup window.
window.top -> returns the topmost window, if you're using frames, this is the frameset window, if not using frames, this is the same as window or self.
window.parent -> returns the parent frame of the current frame or iframe. The parent frame may be the frameset window or another frame if you have nested frames. If not using frames, parent is the same as the current window or self
when you are dealing with popups window.opener plays an important role, because we have to deal with fields of parent page as well as child page, when we have to use values on parent page we can use window.opener or we want some data on the child window or popup window at the time of loading then again we can set the values using window.opener

How to get the references of all opened child windows after parent window reload

I am storing the reference of child window in variable as below.
var mychildWindow = window.open(url,name,params);
When the parent window refresh/reload how to get the child window instance??
Any work around or like Facebook did for pop out chat.
Thanks in advance
Facebook doesn't use (to my knowledge) window.open - they use panels - floating divs a layer above the main content - have a look at the YUI Panel for an example.
If you have control over both windows, the child window can send a beacon to the parent on an interval: "I'm your child, I'm your child, I'm your child".
http://abcoder.com/javascript/maintain-reference-to-popup-window-over-page-refresh-or-redirect-in-javascript-solved
Unfortunately, I'm opening potentially any url in the child window, so I don't have control over that.

Initiating a connection between two browser windows in Javascript

I understand that if one window opens another that the opened window the return value of .open(path).
I also get that the child window can access the parent through window.opener.
However, in the event that the parent has since been closed, and another window (or tab) from the same domain has been opened, is there any way to grant access from one window to another in a horizontal fashion? Maybe by passing a reference through a cookie or something?
Thanks.
No, sorry. If you don't have a reference to the window there's no way to get it. You can still send messages to another tab, however, via HTML5's localStorage events
If you in the parent have
window.name="myParentWindow"
the child can do
var parentHandle = (window.opener && !window.opener.closed) ? window.opener :
window.open("","myParentWindow");

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