是否可以设置一个基本的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>
其他回答
这是前面所有答案的总结,加上通过.htaccess使用HTTP Refresh Header的附加解决方案
HTTP刷新标头首先,您可以使用.htaccess设置这样的刷新标头标题集刷新“3”这相当于在PHP中使用header()函数标头(“刷新:3;”);请注意,并非每个浏览器都支持此解决方案。JavaScript使用备用URL:<脚本>setTimeout(function){location.href=“http://example.com/alternate_url.html"} , 3000);</script>没有备用URL:<脚本>setTimeout(“location.reload(true);”,timeoutPeriod);</script>使用窗口对象:<脚本>window.location.reload(true);</script>刷新标识当不需要依赖JavaScript和重定向头时,可以使用元刷新使用备用URL:<meta http equiv=“刷新”content=“3;url=http://example.com/alternate_url.html">没有备用URL:<meta http equiv=“刷新”content=“3”>使用<noscript>:<noscript><meta http equiv=“refresh”content=“3”/></noscript>
可选
根据Billy Moon的建议,如果出现问题,您可以提供刷新链接:
如果未自动重定向:<a href='http://example.com/alternat_url.html'>单击此处</a>
资源
维基百科元刷新META REFRESH的性能影响使用jQuery刷新(重新加载)一次页面?
尝试使用:
<meta http-equiv="refresh" content="0; url=http://example.com/" />
注意:将其放在<head>部分。
此外,对于较旧的浏览器,如果您添加了一个快速链接,以防无法正确刷新:
<p><a href=“http://example.com/“>重定向</a></p>
将显示为
重新使用
这仍然允许您通过额外的点击到达您要去的地方。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Redirect to a page</title>
</head>
<body onload="window.location.assign('http://example.com')">
</body>
</html>
Razor引擎延迟5秒:
<meta http-equiv="Refresh"
content="5; url=@Url.Action("Search", "Home", new { id = @Model.UniqueKey }))">
你应该使用JavaScript。将以下代码放在头标签中:
<script type="text/javascript">
window.location.assign("http://www.example.com")
</script>