是否可以设置一个基本的HTML页面以在加载时重定向到另一个页面?
当前回答
只是为了更好地衡量:
<?php
header("Location: http://example.com", true, 302);
exit;
?>
确保脚本上方没有echo,否则将忽略它。http://php.net/manual/en/function.header.php
其他回答
据我所知,迄今为止,我所看到的所有解决这个问题的方法似乎都在历史中添加了老位置。要重定向页面,但在历史记录中没有旧位置,我使用替换方法:
<script>
window.location.replace("http://example.com");
</script>
JavaScript
<script type="text/javascript">
window.location.href = "http://example.com";
</script>
Meta标记
<meta http-equiv="refresh" content="0;url=http://example.com">
适用于所有类型页面的简单方法是在头部添加一个元标记:
<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>
Razor引擎延迟5秒:
<meta http-equiv="Refresh"
content="5; url=@Url.Action("Search", "Home", new { id = @Model.UniqueKey }))">
推荐文章
- 防止滚动条增加到Chrome页面的宽度
- 使用图像而不是单选按钮
- 我可以嵌套一个<按钮>元素内< >使用HTML5?
- 设置TextView文本从html格式的字符串资源在XML
- 为什么我的球(物体)没有缩小/消失?
- Twitter Bootstrap 3 Sticky Footer
- CSS在特定的“内联块”项之前/之后换行
- 很好的初学者教程socket.io?
- 点击下载Href图片链接
- HtmlSpecialChars在JavaScript中等价于什么?
- 我如何删除背景图像在css?
- 如何克服HTML表单嵌套的限制?
- 如何使Bootstrap 4卡在卡列相同的高度?
- 使用域集图例引导
- 音频停止功能