Home > Article > Web Front-end > How to delay jump in javascript
In JavaScript, you can use the setTimeout() function in conjunction with the "location.href" attribute to implement delayed jumps. The syntax is "setTimeout(function(){window.location.href='jump address';}, delay milliseconds);".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
javascript for delayed jump
In javascript, you can use the setTimeout() method with the window.location.href attribute to implement delayed jump.
Implementation code:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JavaScript</title> </head> <html> <body> <p>5s后跳转跳转</p> <script type="text/javascript"> setTimeout(function(){ window.location.href='https://www.php.cn/'; },5000); // function jump(){ // window.location.href='https://www.php.cn/'; // } // setTimeout(jump,5000); </script> </body> </html>
Description:
setTimeout() method is used to specify The number of milliseconds after which a function or calculated expression is called.
Tips:
1000 milliseconds = 1 second.
If you only want to repeat the execution, you can use the setInterval() method.
Use the clearTimeout() method to prevent the execution of the function.
[Recommended learning: javascript advanced tutorial]
The above is the detailed content of How to delay jump in javascript. For more information, please follow other related articles on the PHP Chinese website!