如何让页面在X秒后让用户跳转到新的网页。如果可能的话,我想使用HTML,但是一种愚蠢的感觉告诉我它必须是Javascript。
到目前为止,我有以下内容,但没有时间延迟
<body onload="document.location='newPage.html'">
答案 0 :(得分:13)
元刷新很难看,但会起作用。以下内容将在5秒后转到新网址:
<meta http-equiv="refresh" content="5;url=http://example.com/"/>
答案 1 :(得分:3)
如果你要使用JS路线,只需使用
setTimeout("window.location.href = 'newPage.html';", 5000);
答案 2 :(得分:1)
把它放在头上:
<meta http-equiv="refresh" content="5;url=newPage.html">
这将在5秒后重定向。使0重定向onload。
答案 3 :(得分:1)
你可以使用好的'META REFRESH,不需要JS,虽然这些(我认为)已被弃用。
答案 4 :(得分:1)
Meta Refresh是可行的方法,但这里是JavaScript解决方案:
<body onload="setTimeout('window.location = \'newpage.html\'', 5000)">
可以找到更多详细信息here。
答案 5 :(得分:0)
JavaScript方法,无需在eval
:
setTimeout
<body onload="setTimeout(function(){window.location.href='newpage.html'}, 5000)">