Is there any way/workaround to close a window that has not been opened by JavaScript using the open methodwindow.open
?
Any help in this regard is much appreciated!
Requirment:-
I am working on struts2 application that has two jsp pages namely:-
- Security token page, calling it as PAGE1
- Generate password page, calling it as PAGE2
PAGE1 has some token related fields and a continue button. User enters his token number and hits the continue button. Code performs a mix of server side and client side validations. Basic JavaScript validations like field not empty and invalid number etc. followed server side validation of the security token. when this validation succeeds. The struts action takes it to the next page, that is, PAGE2.
Note:- That this page was not created by JavaScript using window.open()
method but by struts framework action method.
Now, on PAGE2 there is a close button. Here the user has an option to leave/abandon the page on click of the close button.
But I am not able to close this window using JavaScript as I mentioned earlier "this page was not opened by the JavaScript using open method."
I tried a workaround like this:-
Noticed that window.close()
--> closes the window in IE
But not in chrome and Firefox
I also tried:-
var win = window.open("about:blank", "_self"); win.close();
But this doesn’t actually close the parent window it just replace with a blank new window in Firefox/chrome, closes the window in IE. I have search and found that a reference to the window my close the window. But the question yet remains “How can a reference of widow generated by struts2 action be found”? my guess was this
var win = window.open(window.location.href,"_self"); win.close();
But this also did not work, unfortunately!
Comment: - "Without a reference to the window, you can't find it again, by name or otherwise" JavaScript - Reference Browser Window by name?