Javascript method to jump to the page after 5 seconds: [var div = document.querySelector('div'); var time = 5; timer(); setInterval(timer, 1000) ...].
#The operating environment of this article: windows10 system, thinkpad t480 computer.
In the development of many projects, we often need to realize the effect of automatic page jump. The following code realizes the effect of automatic page jump after 5 seconds. Let’s take a look!
The specific code is as follows:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <div></div> <script> var div = document.querySelector('div'); var time = 5; timer(); setInterval(timer, 1000) function timer() { if (time == 0) { location.href = 'http://www.baidu.com' } else { div.innerHTML = '将在' + time + '秒后跳转到百度'; time--; } } </script> </body> </html>
Recommended learning: javascript video tutorial
The above is the detailed content of How to jump to the page after 5 seconds in javascript. For more information, please follow other related articles on the PHP Chinese website!