3

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

Community
  • 1
  • 1
BlueFox
  • 161
  • 1
  • 2
  • 12

3 Answers3

4

try 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");
Sidius
  • 416
  • 1
  • 5
  • 24
  • Your edit gets blocked as well. I guess this is due to the Firefox security options in our company. – BlueFox Dec 03 '15 at 16:08
  • See this link here: https://developer.mozilla.org/en-US/docs/Web/API/Window/open If this also doesn't work, you will be definitely right. @BlueFox – Sidius Dec 03 '15 at 16:11
2

You can use setTimeout() API to achieve the same -

setTimeout(window.close,3000);
Murli
  • 1,258
  • 9
  • 20
1

You need to use window.setTimeout():

window.open('', '_self', '');
// Add this instead.
setTimeout(function(){
   window.close(); 
}, 3000);
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252