Reputation: 1439
I have a PHP page which opens an HTML page on top of it or i should say it opens the html page on same browser tab. I want, when the html page loads the browser tab should automatically close after 5 seconds.
Upvotes: 5
Views: 27535
Reputation: 1
After some time, your page will auto closed. You should try this:
<script type="text/javascript">
window.setTimeout('window.location="/<!--Enter another page that will be opened after this page is closed-->"; ',3500<!--this is how long before it's closed-->);
</script>
example:
<script type="text/javascript">
window.setTimeout('window.location="/Lab%20/index.php"; ',5000<!--this is how long before it's closed, 5000 for 5sec-->);
</script>
Upvotes: 0
Reputation: 131
Tried the onload event: it does not work, it executes immediately, even if you do a "setTimeout".
Turned out to be very simple, just add a script tag to your body:
<script>
setTimeout(function() {
window.close()
}, 5000);
</script>
after it loads it executes the script and waits 5 seconds before it exits.
Upvotes: 5
Reputation: 100
You need JavaScript. put some javascript code in your html that will open in new tab. then the code will wait for page to load and wait another 5 second to close the tab.
<html>
<head>
</head>
<body onload="waitFiveSec()"> <!--it will wait to load-->
<!-- your html... -->
<script>
function waitFiveSec(){
setTimeout(function, milliseconds) /*(here you need to implement delay code)*/
window.close();
}
</script>
</body>
</html>
here is some links you may need :
https://www.w3schools.com/js/js_timing.asp
https://www.w3schools.com/jsref/event_onload.asp
Upvotes: 4