I try to set up a simple logoff-page which should close after 3 seconds.
Regarding this Question is it possible to wait before that action?
<script type="text/javascript">
sleep(3000);
window.open('', '_self', '');
window.close();
</script>
With the sleep nothing happens at all.
Edit:
The solution of @Sidius works well in IE without a prompt.
Unfortunately Firefox blocks the Script:
Scripts can not close any windows that were not opened by the script
I try to set up a simple logoff-page which should close after 3 seconds.
Regarding this Question is it possible to wait before that action?
<script type="text/javascript">
sleep(3000);
window.open('', '_self', '');
window.close();
</script>
With the sleep nothing happens at all.
Edit:
The solution of @Sidius works well in IE without a prompt.
Unfortunately Firefox blocks the Script:
Share Improve this question edited May 23, 2017 at 12:07 CommunityBot 11 silver badge asked Dec 3, 2015 at 15:17 BlueFoxBlueFox 1711 gold badge2 silver badges13 bronze badges 5Scripts can not close any windows that were not opened by the script
-
1
window.setTimeout(function(){},time);
? – www139 Commented Dec 3, 2015 at 15:19 - Are you saying that the new window opens, it waits 3 seconds and then closes? – www139 Commented Dec 3, 2015 at 15:21
- Does that hack to close a browser you did not open really still work? – epascarello Commented Dec 3, 2015 at 15:23
- @www139 nothing happens. – BlueFox Commented Dec 3, 2015 at 15:42
- Check my edited answer @BlueFox – Sidius Commented Dec 3, 2015 at 15:51
3 Answers
Reset to default 4try this:
window.open('', '_self', '');
setTimeout(function(){
window.close();
}, 3000);
Edit: I think firefox might be a little more strict with the
window.open()
function. You might want to give values to the function's constructor.
window.open(URL,name,specs,replace);
In example:
window.open("", "", "width=200, height=100");
You can use setTimeout() API to achieve the same -
setTimeout(window.close,3000);
You need to use window.setTimeout()
:
window.open('', '_self', '');
// Add this instead.
setTimeout(function(){
window.close();
}, 3000);