简体   繁体   中英

using php within setTimeout in javascript

I have an issue using my php code within the javascript function setTimeout. The code is in a php file, but instead of acting like it should and waiting the five minutes to send the user to the index page of my website, it just does it instantly. Any ideas?

Here's the code:

<script>
  setTimeout(function() { <?php header( 'Location: /index.html' ); ?> }, 300000);
</script>  

Yes. It is because the PHP Code first gets executed, because it is server-side. So you would have to modify your code:

<script>
  setTimeout(function() { window.location.href='/index.html'  }, 300000);
</script>  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM