javascript 如何在 5 分钟后重定向到另一个页面?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4866572/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 15:09:17  来源:igfitidea点击:

How to redirect to another page after 5 minutes?

phpjavascripthtmltimer

提问by bsanneh

How do I redirect to another page after 5 minutes using PHP?

如何在使用 PHP 5 分钟后重定向到另一个页面?

回答by kayahr

If you really want to use PHP for this, here you go:

如果您真的想为此使用 PHP,请执行以下操作:

<?php header("Refresh: 300; URL=http://www.stackoverflow.com/"); ?>

回答by Arnaud Le Blanc

With just HTML:

仅使用 HTML:

<meta http-equiv="refresh" content="300;http://redirect-url" />

This will redirect to http://redirect-urlafter 300 seconds (5 minutes).

这将http://redirect-url在 300 秒(5 分钟)后重定向到。

回答by Will Charczuk

Javascript's setTimeout() is probably what you want. An example would be:

Javascript 的 setTimeout() 可能就是你想要的。一个例子是:

setTimeout(function(){ window.location = "<URL HERE>";}, 5*60*1000);

window.location is what you can use in javascript to set the current location of the window. Something to consider, however, is that most browsers do not let you set window.location without some type of user input before hand, such as a click.

window.location 是你可以在 javascript 中用来设置窗口当前位置的东西。但是,需要考虑的是,大多数浏览器不允许您在没有事先进行某种类型的用户输入(例如单击)的情况下设置 window.location。

See here

这里