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

How to delay jump in javascript

青灯夜游
Release: 2023-01-07 11:47:25
Original
5520 people have browsed it

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;//m.sbmmt.com/&#39;;
},5000);

//  function jump(){
//     window.location.href=&#39;//m.sbmmt.com/&#39;;
// }
// setTimeout(jump,5000);
</script>
</body>
</html>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template