You are here: irt.org | FAQ | JavaScript | Timeout | Q546 [ previous next ]
<form onSubmit="setTimeout('window.close',5000)"> <input type="submit" value="Close Window"> </form>
Because JavaScript has no way of knowing when the form has finished beinging submitted - therefore a guesstimate of the amount of time required for the form submit is chosen (5 seconds) and a time is set up to close the window after 5 seconds has passed. However, on a slow day the form may still not have been submitted within the 5 seconds, the closing of the window will interrupt the form submission and it will fail.