Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wait/sleep before window.close()

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

like image 285
BlueFox Avatar asked Mar 01 '26 17:03

BlueFox


2 Answers

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");
like image 186
Sidius Avatar answered Mar 03 '26 06:03

Sidius


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

setTimeout(window.close,3000);
like image 40
Murli Avatar answered Mar 03 '26 06:03

Murli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!