是否可以设置一个基本的HTML页面以在加载时重定向到另一个页面?
当前回答
位于头部内部的以下元标记将告诉浏览器重定向:
<meta http-equiv="Refresh" content="seconds; url=URL">
将秒替换为重定向前等待的秒数,并将URL替换为要重定向到的URL。
或者,您可以使用JavaScript重定向。将其放置在页面上的任意位置的脚本标记中:
window.location = "URL"
其他回答
将以下代码放入<head>部分:
<meta http-equiv="refresh" content="0; url=http://address/">
这不需要任何JavaScript代码。将其写入HTML页面的<head>部分:
<meta http-equiv="refresh" content="0; url=example.com" />
页面在0秒加载后,即可转到页面。
最好设置301重定向。请参阅谷歌网站管理员工具文章301重定向。
适用于所有类型页面的简单方法是在头部添加一个元标记:
<html>
<head>
...
<meta HTTP-EQUIV="REFRESH" content="seconds; url=your.full.url/path/filename">
...
</head>
<body>
Don't put much content, just some text and an anchor.
Actually, you will be redirected in N seconds (as specified in content attribute).
That's all.
...
</body>
</html>
我使用一个脚本将用户从index.html重定向到登录页面的相对url
<html>
<head>
<title>index.html</title>
</head>
<body onload="document.getElementById('lnkhome').click();">
<a href="/Pages/Login.aspx" id="lnkhome">Go to Login Page</a>
</body>
</html>