I'm just getting into Java. I'm working on a simple script to open a window, then close it after a short delay. I've tried various connotations of the following with no avail. The function works (in that it opens, then closes the window) but the delay fails to happen.
function manualWindow(){
testWindow = window.open("popup.php","interaction","resizable=0,width=800,height=600,status=0");
setTimeout(testWindow.close(),5000);
}
thank you
You want:
setTimeout(function() { testWindow.close(); },5000);
You current code is executing that function as soon as it is hit and then trying to run it's return value after the delay. By wrapping it up in the function it will be run correctly after 5 seconds.
Example:
<html>
<head></head>
<body>
<script type="text/javascript">
function manualWindow(){
testWindow = window.open("http://www.google.co.uk","interaction","resizable=0,width=800,height=600,status=0");
setTimeout(function() { testWindow.close() },5000);
}
manualWindow();
</script>
</body>
</html>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With