在一段时间后redirect网站

我需要做什么才能在网站上有一个function,它表示将在3秒左右将您redirect到网站?

<meta http-equiv="refresh" content="3;url=http://www.google.com/" /> 

您可能正在寻找meta refresh标记 :

 <html> <head> <meta http-equiv="refresh" content="3;url=http://www.somewhere.com/" /> </head> <body> <h1>Redirecting in 3 seconds...</h1> </body> </html> 

请注意,使用meta refresh在这些日子已被弃用和皱眉,但有时它是唯一可行的select(例如,如果您无法执行HTTPredirect头的服务器端生成和/或您需要支持非JavaScript客户等)。

如果你想要更好的控制,你可以使用JavaScript而不是使用元标记。 这可以让你有一个视觉上的某种东西,例如倒计时。

这是一个非常基本的方法,使用setTimeout()

 <html> <body> <p>You will be redirected in 3 seconds</p> <script> var timer = setTimeout(function() { window.location='http://example.com' }, 3000); </script> </body> </html> 

这是一个完整的(但简单的)X秒后redirect的例子,同时更新一个计数器div:

 <html> <body> <div id="counter">5</div> <script> setInterval(function() { var div = document.querySelector("#counter"); var count = div.textContent * 1 - 1; div.textContent = count; if (count <= 0) { window.location.href="https://example.com"; } }, 1000); </script> </body> </html> 

counter div的初始内容是等待的秒数。

最简单的方法是使用这样的HTML META标签:

 <meta http-equiv="refresh" content="3;url=http://example.com/" /> 

维基百科

在HTML代码的和标记之间放置以下HTMLredirect代码。

<meta HTTP-EQUIV="REFRESH" content="3; url=http://www.yourdomain.com/index.html">

上面的HTMLredirect代码会立即将您的访问者redirect到另一个网页。 内容=“3”可能会改变为浏览器在redirect之前需要等待的秒数4,5,8,10或15秒等等。

使用这个简单的JavaScript代码,使用特定的时间间隔redirect页面到另一个页面…

请将此代码添加到您要redirect的网站页面中:

 <script type="text/javascript"> (function(){ setTimeout(function(){ window.location="http://brightwaay.com/"; },3000); /* 1000 = 1 second*/ })(); </script>