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.
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.
- 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 Commented May 16, 2012 at 5: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 Commented May 16, 2012 at 5:14
-
Why you open new document in current window (
'_self'
)? – Andrew D. Commented May 16, 2012 at 5: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 Commented May 16, 2012 at 6:00
- top.close(); seems to work... – Mint Commented May 16, 2012 at 6:01
3 Answers
Reset to default 3I found that this works
top.close();
From within the browser address bar
javascript:top.close();
I don't know why, but the example from the link below didn't work for me.
http://www.w3schools./jsref/met_win_close.asp
Worked:
window.close();
Didn't worked:
myWindow.close();
A better presentation:
onclick="javascript: window.open('', '_self', ''); window.close();"