Home  >  Article  >  Web Front-end  >  How to delay jump in javascript

How to delay jump in javascript

青灯夜游
青灯夜游Original
2021-09-07 13:58:535518browse

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);".

How to delay jump in javascript

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=&#39;https://www.php.cn/&#39;;
},5000);

//  function jump(){
//     window.location.href=&#39;https://www.php.cn/&#39;;
// }
// setTimeout(jump,5000);
</script>
</body>
</html>

How to delay jump in javascript

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn