使用 JS : (在 <head>
标签中)
<script>window.location="https://stackoverflow.com";</script>
使用 PHP : (在 <head>
标签中)
header('Location: https://stackoverflow.com');
end();
我应该使用哪一个?或其他 ?
那么使用 <meta>
怎么样?
<meta http-equiv="refresh" content="0;url=https://stackoverflow.com"/>
很多好的答案,我不知道我会接受哪个答案,非常感谢
原文由 l2aelba 发布,翻译遵循 CC BY-SA 4.0 许可协议
所有选项的结果都是相同的。重定向。
<meta>
在 HTML 中:window.location
在JS中:if (1 === 1) { window.location.href = 'http://example.com'; }
。header('Location:')
在 PHP 中:header()
必须是 php 脚本中的第一个命令,然后才能输出任何其他命令。如果您尝试在标头之前输出一些内容,将收到Warning: Cannot modify header information - headers already sent