这里有新鲜出炉的 PHP 教程,程序狗速度看过来!
PHP(外文名: Hypertext Preprocessor,中文名:"超文本预处理器")是一种通用开源脚本语言。语法吸收了 C 语言、Java 和 Perl 的特点,入门门槛较低,易于学习,使用广泛,主要适用于 web 开发领域。PHP 的文件后缀名为 php。
下面小编就为大家带来一篇用 html/JS/PHP 方式实现页面延时跳转的简单实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
WEB 开发中经常会遇到页面跳转或延时跳转的需求,掌握各种页面跳转方式非常必要。
以下是我总结有用 HTML/JS/PHP 三类方式实现跳转的方法,例子皆为三秒后跳转到 index.php 页面。
1,HTML 方法:
在 HEAD 中添加 <meta> 标签
- <meta http-equiv="refresh" content="3;url='index.php' ">
2,JS 控制跳转方法
A.Location 直接加链接方式
- <script type="text/javascript">
- setTimeout("window.location=('index.php'",3000);
- </script>
B.Location.href 方式
- <script type="text/javascript">
- setTimeout("window.location.href='index.php'",3000);
- </script>
C.Location.assign 方式
- <script type="text/javascript">
- setTimeout("window.location.assign('index.php')",3000);
- </script>
D.Location.replace 方式(注意页面是被 "替换" 掉了,不会在浏览器的历史记录被查询到)
- <script type="text/javascript">
- Widdow.location.replace('index.php ');
- '
- </script>
E.JS 历史记录 go(n) 方式(n 表示对历史记录相对当前页的前进步数,n 为负数表示返回以前的页面)
- <script type="text/javascript">
- window.history.go(n);
- </script>
F.JS 历史记录 go(url) 方式(注意 url 必须是历史记录内的,不然页面不会进行跳转)
- <script type="text/javascript">
- window.history.go('index.php ');
- '
- </script>
G.JS window.open 方式,通过打开一个新窗口,实现跳转。(其第二个属性为可选目标选项,值可以是 frame id/_blank 等,第三个选项为新弹出窗口的具体设置选项,包括 height/width 等)
- <script type="text/javascript">
- setTimeout("window.open('index.php',target,args)",3000);
- </script>
3,PHP 脚本控制跳转方式,通过改写 HTTP 头信息来进行跳转
A.header refresh 方式:
- Header("refresh: 3; url = 'index.php'");
B. header location 方式 :
- sleep(3);
- Header("location: index.php");
要注意这种方式会导致无法进入当前页面。即若当前在 register.php 页面链接到 login.php 页面时,login.php 页面内用 header location 方式跳转,页面会从 register.php 页面直接等待三秒跳转到 index.php,不会进入到 login.php 页面,这是因为 header location 会对页面进行重定向。
如有错误,欢迎指正,谢谢。
以上这篇用 HTML/JS/PHP 方式实现页面延时跳转的简单实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持 PHPERZ。
来源: http://www.phperz.com/article/17/0731/343278.html