HTML / JavaScript / PHP 实现页面跳转的几种方式
2015-10-18 17:28
771 查看
① HTML 的 meta refresh 标签
"1; url = http://www.baidu.com" 代表 1s 以后跳转至百度,http 的状态码是 302。
② JavaScript 的 window.location
同样也是 1s 以后跳转至百度,http 状态码也是 302。
③ PHP 的 header
1s 以后跳转至百度,http 状态码也是 302。
或者
表示直接跳转至百度,http 状态码也是 302。
如果要把 http 状态码改为 301,可以:
<!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); ?>
相关文章推荐
- 一点用JS写控制权限的心得
- [LeetCode][JavaScript]Remove Duplicates from Sorted Array
- [LeetCode][JavaScript]Remove Duplicates from Sorted Array II
- JS编程去掉注释部分
- JSP之应用Servlet过滤器进行身份验证
- JSON数据解析(GSON方式) (转)
- html+js实现四则元算计算器
- js错误处理
- Ember.js 入门指南——定义模型
- js拖拽实现
- javascript 实现一个网页,然后计算出有多少剩余时间的倒计时程序
- JS中如何输出空格
- JSP的内置对象
- 你不知道的JavaScript--Item11 arguments对象
- 你不知道的JavaScript--Item11 arguments对象
- js定时器 setTimeout
- 详解js闭包
- fullpage.js
- javascript中获取Dajango里Tastypie所传过来的数据
- JSP自定义标签详解