2

It works in Chrome and I thought it used to work in IE8... but it doesn't seem to.

javascript:window.open('', '_self', ''); window.close();alert('test');

All I get is the alert.

Basically i'm trying to execute a function which works fine in the browser as an a link, but using the same code in captivates "execute javascript" on a button, doesn't work.

Then I thought I would test it using javascript: in IE... and it doesn't close it ether.

Whats going on?
It's driving me nuts.

Mint
  • 14,388
  • 30
  • 76
  • 108
  • It should not work, it is a bug. You should not be able to close a window you did not create since you destroy a user's history. – epascarello May 16 '12 at 05:08
  • It's a client requirement so I can't really work around it, as much as I may hate the idea. and they have it done on other projects so they wont understand why it cant work now. I'v done it before and it works. It just doesn't seem to now. – Mint May 16 '12 at 05:14
  • Why you open new document in current window (`'_self'`)? – Andrew D. May 16 '12 at 05:46
  • It's meant to be a work around to the "do you really want to close this window" popup. Another client requirement. These are all internal sites. – Mint May 16 '12 at 06:00
  • top.close(); seems to work... – Mint May 16 '12 at 06:01

3 Answers3

3

I found that this works

top.close();

From within the browser address bar

javascript:top.close();
Mint
  • 14,388
  • 30
  • 76
  • 108
  • That's because you gave a blank name for the window (`window.open('', ..)`). – rxgx May 16 '12 at 23:54
  • I donot know why but I followed example from here but it didnot work... http://www.w3schools.com/jsref/met_win_close.asp .... but window.close(); worked for me but not myWindow.close(); – Ziggler Apr 13 '16 at 20:30
0

I don't know why, but the example from the link below didn't work for me.

http://www.w3schools.com/jsref/met_win_close.asp

Worked:

window.close();

Didn't worked:

myWindow.close();
Mint
  • 14,388
  • 30
  • 76
  • 108
Ziggler
  • 3,361
  • 3
  • 43
  • 61
-2

A better presentation:

onclick="javascript: window.open('', '_self', ''); window.close();"