PHP实现重定向网页转向redirect
- 2020-01-02 08:00:00
- zstmtony 原创
- 8241
1.直接使用header("Location
<?php
header("Location: http://www.office-cn.net/t/pro/");?>
或做成一个通用函数
以下使用 PHP header 函数重定向:
function redirect($url) { header("Location: $url"); exit(); }
延迟跳转(比如登陆成功后会有几秒钟等待时间,然后跳转到了其他页面)
<?php header("Refresh:秒数;url=地址") ?> 例如 <?php header("Refresh:3;url=http://www.office-cn.net/t/pro/")?> 会在3秒后执行跳转 <?php sleep(3); header("location:http://www.office-cn.net/t/pro/")?> 调用了sleep()方法,效果也是x秒后执行跳转
在js脚本代码中实现
1.window.location.href方法
<script type="text/javascript"> window.location.href="https://www.52help.net" </script>
使用js方法实现延迟跳转
<script type="text/javascript"> setTimeout("window.location.href='https://www.52help.net'",3000); </script>
2.window.location.assign方法 延迟跳转方法同上
<script type="text/javascript">window.location.assign("https://www.52help.net"); </script>
3.window.location.replace方法 (让新页面替换掉当前页面,不会保存在历史记录里,所有不能使用浏览器后退到原页面了)
<script type="text/javascript"> window.location.replace("https://www.52help.net"); </script>
4.window.open方法 三个参数,第一个URL地址。第二个打开新页面方式(比如新页面_blank,_new,自身跳转_self),第三个是新页面的方式,包括样式,位置等。
<script type="text/javascript"> window.open("index.php",_blank,width=300px); </script>
使用HTML脚本代码完成跳转
在<head>标签里执行代码
直接插入这句代码就可以
<meta http-equiv="refresh" content="3;url='https://www.52help.net'">
发表评论
文章分类
联系我们
联系人: | 王先生 |
---|