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).
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.
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
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.
I'm not the most javascript savy. I've seen posts for children windows getting parent values but not vice versa.
Basically, I want to invoke a window object with window.open. After some user input is entered in the new window, I want to stuff that input into the original window that invoked the window.open.
The only ways I can think to do this are messy. I don't need any code examples. But if it is possible and you can example it to me I would be grateful.
When you open a new window, window.opener contains a reference to the parent window (i.e. the window that opened this window).
Normally when a window is opened using window.open I can access the caller window by using window.opener(), is it possible do the similar within modal dialogs(window.showModalDialog)?
As you can read in a comment on the MSDN page about showModalDialog (thanks to Pekka),
[t]he window.opener method returns
null, rather than a reference to the
opening window. So you cannot refresh
the opening window with
window.opener.location.refresh()
(if, for instance, you use
showModalDialog to open an editing
dialog). If all you want to do is
refresh the opening window every time
the ModalDialog closes, that is easy
(include window.location.refresh()
right after the call to
showModalDialog). But if you only
want to refresh the opening window in
certain cases (e.g., the opening
window takes a while to refresh), you
can do that by passing a
dialogArgument.
A more clever (I think) way is to
pass the window reference itself as the dialogArgument. In the
calling window, use
window.showModalDialog('newurl.asp',
window). In the called dialog
retrieve the reference with var
window_opener =
window.dialogArguments. You can use
the window reference stored in
variable window_opener in place of
window.opener, to refresh the
calling window from the called dialog.
Do note that Firefox and Chrome (for
instance) do not appear to have these
limitations, and appear to treat
ModalDialogs more like regular
windows. Keep that in mind if you do
testing using one of these browsers,
but intend your application to work in
all browsers.