I want to auto-close window after users confirm password changed, so
<script>
alert('password changed!');
window.opener = window.location.href;
self.close();
</script>
It works in IE, but not works in Chrome.
<script>
window.open('', '_self', '');
window.close();
</script>
this not works , too
why not works in Chrome ? & How can i work this?
I want to auto-close window after users confirm password changed, so
<script>
alert('password changed!');
window.opener = window.location.href;
self.close();
</script>
It works in IE, but not works in Chrome.
<script>
window.open('', '_self', '');
window.close();
</script>
this not works , too
why not works in Chrome ? & How can i work this?
Share Improve this question asked Oct 18, 2013 at 14:13 myggulmyggul 3871 gold badge5 silver badges23 bronze badges 1- I don't know about Chrome, but in Opera there is a setting to allow or disallow some JS function, for example to close a window. Maybe this is not working because there is some similar setting in Chrome. – feeela Commented Oct 18, 2013 at 14:16
2 Answers
Reset to default 3Under normal circumstances, JavaScript can only close a window that was opened by JavaScript. While certain "hacks" may exist involving window.opener
or "opening" a new window in the current tab, they are unreliable because they are bypassing a security thing.
In any case, window.close()
should either close the window (if it was opened by JavaScript), or pop up a confirmation asking if the user wants to allow the page to be closed.
I know it is very late to answer this question. But just in case, it helps somebody in future.
It is not possible to close the self window with the same javascript. It is considered as the security issue. It was a bug in the previous versions of the browsers that it used to work then. But it was fixed later. Now, it is not possible to close the "self" window using Javascript.
You can refer to the following stackoverflow answer for more information on this: Answer posted on some other similar question on the stackoverflow.
Hope it clarifies.