是否可以设置一个基本的HTML页面以在加载时重定向到另一个页面?
当前回答
将以下代码放入<head>部分:
<meta http-equiv="refresh" content="0; url=http://address/">
其他回答
我使用一个脚本将用户从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>
一旦页面加载,init函数就会启动并重定向页面:
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<script>
function init()
{
window.location.href = "www.wherever.com";
}
</script>
</head>
<body onload="init()">
</body>
</html>
只是为了更好地衡量:
<?php
header("Location: http://example.com", true, 302);
exit;
?>
确保脚本上方没有echo,否则将忽略它。http://php.net/manual/en/function.header.php
位于头部内部的以下元标记将告诉浏览器重定向:
<meta http-equiv="Refresh" content="seconds; url=URL">
将秒替换为重定向前等待的秒数,并将URL替换为要重定向到的URL。
或者,您可以使用JavaScript重定向。将其放置在页面上的任意位置的脚本标记中:
window.location = "URL"
您可以使用META“重定向”:
<meta http-equiv="refresh" content="0; url=http://new.example.com/address" />
或JavaScript重定向(请注意,并非所有用户都启用了JavaScript,因此始终为他们准备备份解决方案)
<script language="javascript">
window.location = "http://new.example.com/address";
</script>
但如果您有选择,我建议您使用mod_rewrite。
推荐文章
- 创建圈div比使用图像更容易的方法?
- 为什么Chrome浏览器不正确地确定页面是在不同的语言,并提供翻译?
- 在网页上用鼠标模拟震颤(例如帕金森病)?
- Bootstrap抛出Uncaught错误:Bootstrap的JavaScript需要jQuery
- 如何改变文本区域的边框颜色:焦点
- 我如何设置背景颜色为文本的宽度,而不是整个元素的宽度,使用CSS?
- 如何删除和清除所有的本地存储数据
- 强制打开“另存为…”弹出打开文本链接点击PDF在HTML
- 如何修改标签文本?
- 在HTML中还有其他有用的空格码吗,比如半空格的 , em-spaces, en-spaces等等?
- 输入触发器按钮单击
- Angular 2模板中的标签是什么意思?
- 如何设置身体高度溢出滚动
- 发送字符串到stdin
- 在输入type="number"时禁用webkit的旋转按钮?