【发布时间】:2010-09-13 11:14:45
【问题描述】:
如何使页面在 X 秒后让用户跳转到新网页。如果可能的话,我想使用 HTML,但有一种感觉告诉我它必须是 Javascript。
到目前为止我有以下但没有时间延迟
<body onload="document.location='newPage.html'">
【问题讨论】:
标签: javascript html
如何使页面在 X 秒后让用户跳转到新网页。如果可能的话,我想使用 HTML,但有一种感觉告诉我它必须是 Javascript。
到目前为止我有以下但没有时间延迟
<body onload="document.location='newPage.html'">
【问题讨论】:
标签: javascript html
元刷新很难看,但会起作用。以下内容会在 5 秒后跳转到新的 url:
<meta http-equiv="refresh" content="5;url=http://example.com/"/>
【讨论】:
如果你要走 JS 路线,请使用
setTimeout("window.location.href = 'newPage.html';", 5000);
【讨论】:
把它放在头上:
<meta http-equiv="refresh" content="5;url=newPage.html">
这将在 5 秒后重定向。使 0 重定向 onload。
【讨论】:
你可以使用好的 ole'META REFRESH,不需要 JS,虽然那些(我认为)已被弃用。
【讨论】:
元刷新是可行的方法,但这里是 JavaScript 解决方案:
<body onload="setTimeout('window.location = \'newpage.html\'', 5000)">
更多详情请见here。
【讨论】:
JavaScript 方法,没有在setTimeout 中调用eval:
<body onload="setTimeout(function(){window.location.href='newpage.html'}, 5000)">
【讨论】: