1
I am implementing the Jquery UI Dialog in my application. When the dialog is closed it should close the current window using the method window.open();
javascript.
However this does not occur, and the following error is still displayed on the console:
Scripts may close only the windows that were opened by it.
I’ve been searching for the solution on Google for some time, but everything I found was not enough. An example of massively accepted solution that did not solve my problem was the use of the following code (or similar variations):
window.open('', '_self', '');
window.close();
I simplified the code of my application to use example in this fiddle, although the error message is not displayed by Jsfiddle, nor is the window closed.
You have tried using jQuery.Dialog () from jQueryUI ??
– jlHertel
That’s exactly who I’m using.
– mayconfsbrito
The method
window.open
returns the reference to the open window, where you can use thewindow.close
on that same object. You can test that?– Wakim
Down at the fiddle:
parent.window.close();
shoots.– brasofilo
@Brasofilo yes, shoots yes.
– mayconfsbrito
@Wakim which window attribute triggers this reference?
– mayconfsbrito
The very one
window.open
returns the reference to the objectwindow
from the open window. Just save it and use later when you want to close.– Wakim
@Wakim then I can pass it by parameter to the dialog function and use it there?
– mayconfsbrito
Yes, I believe you can pass, because of the call to
dialog
you will "save" it in a closure, I believe that with this the object will be available in the dialog action.– Wakim