2

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?

myggul
  • 387
  • 1
  • 5
  • 22
  • 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 Oct 18 '13 at 14:16

2 Answers2

3

Under 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.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
  • 1
    I am running into this problem on Chrome where `window.close` and `self.close` do not work and despite the statement that it will either close or prompt, neither is happening, so any solution to this? It is mindbogglingly stupid that Chrome is so broken in this manner. – GµårÐïåñ Nov 04 '13 at 03:24
0

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.

Arpit Jain
  • 26
  • 4