码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2015-10-18 18:35:47      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

① 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);
?>

 

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

标签:

原文地址:http://www.cnblogs.com/dee0912/p/4889885.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!