您的位置:首页 > Web前端 > JavaScript

HTML / JavaScript / PHP 实现页面跳转的几种方式

2015-10-18 17:28 771 查看
① HTML 的 meta refresh 标签

<!doctype html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="1; url=http://www.baidu.com">
</head>
<body>
</body>
</html>


"1; url = http://www.baidu.com" 代表 1s 以后跳转至百度,http 的状态码是 302。

② JavaScript 的 window.location

<!doctype html>
<html lang="en">
<head>
</head>
<body>
<script>
setTimeout("window.location.href = 'http://www.baidu.com'", 1000);
</script>
</body>
</html>


同样也是 1s 以后跳转至百度,http 状态码也是 302。

③ PHP 的 header

<?php
header('Refresh:1; url=http://www.baidu.com');
?>


1s 以后跳转至百度,http 状态码也是 302。

或者

<?php
header('Location:http://www.baidu.com');
?>


表示直接跳转至百度,http 状态码也是 302。

如果要把 http 状态码改为 301,可以:

<?php
header('Location:http://www.baidu.com', true, 301);
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: