I want to close the parent window when a new window is opened.
I tried top.window.close() but it did not work for me.
Does anybody here know any other method to get a collection of windows
assume, you have a page called "PageA", in "PageA" you can open "PageB" , by this window.open like window.open("PageB") and in "PageB" you can access the window object of "PageA by this window.opener, and to close "PageA" from "PageB" you can use this window.opener.close(), to see complete window.open sample, read this Window.open API
and to review window.opener see this Window.opener API
Related
I am opening new window pop up using window.open method which will restrict user to use its parent window till the new window is not closed. User will not be able switch back to parent window till child window is open.
How can I do it using JavaScript? please guide me..
To disable the parent window until child window closed you might want to use window.showModalDialog() instead of window.open().
To use showmodalDialog click here
note: However, that you can not use window.opener from a modal dialog box (it will always be null) unless you explicitly pass a reference to the parent window in the second argument to showModalDialog() and get it back using window.dialogArguments.
If I have a script which calls window.open, loading a new page into the same window, then that new page's JavaScript needs to identify the Previous Page's URL - what is the best way to find it?
You can use window.opener.location.href , it will give you the URL of the parent page from which you opened a new window.
You can use window.opener to obtain a reference to the window that opened the current window. Not sure if this is what you are after. When using window.open it will result in a new window, not sure what you mean by "open new window in the same screen".
Using Window.opener you can get it, like
var win=window.open('http://heera.it');
console.log(win.opener.location.href); // will output the url
Example.
I want to open a new window using window.open method which will restrict user to use its parent window till the new window is not closed. User will not be able switch back to parent window while child window is still open.
How can i do it using javascript? please guide me..
If you want the popup window to be modal (i.e. to disable its parent window until it's closed), you might want to use window.showModalDialog() instead of window.open().
Note, however, that you cannot use window.opener from a modal dialog box (it will always be null) unless you explicitly pass a reference to the parent window in the second argument to showModalDialog() and get it back using window.dialogArguments.
The work flow is like this, from my page, I created a popup using window.open method, then open other popup from that window and close its immediate parent, and I need to refresh the first parent page from this popup. I tried in different ways, but the window.opener method can't get the parent windows property.
Can anyone help me to solve this?
Is there any way to close a new tab window that was not opened using window.open();?
No. If you didn't open the window you are not supposed to close it.
Please see here: http://www.infimum.dk/HTML/JSwindows.html#ref_3_11
In order to close a specific window using the window.close() method you need a reference to that window, which you can usually get when opening a window using the window.open() method.
Another option I can see is to use global window/frame references (self, parent, opener, etc...You can see the list in the link above as well).