PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

php怎么实现一个页面跳转到其它页面

王林
王林 原创
2021-02-20 15:03:48 8137浏览

php实现一个页面跳转到其它页面的方法:在php脚本中添加代码【header("location:url地址")】即可。如果要延迟跳转,代码为【header("refresh:秒数;url=地址")】。

本文操作环境:windows10系统、php 7.3、thinkpad t480电脑。

在PHP脚本代码中实现

<?php  
    header("location:url地址") 
?>

例如

<?php  
header("location:helloworld.php")
?>

页面会立即跳转,因为header执行了location重定向。

延迟跳转(比如登陆成功后会有几秒钟等待时间,然后跳转到了其他页面)

<?php  
    header("Refresh:秒数;url=地址")     
?>

例如

<?php   
    header("Refresh:3;url=helloworld.php")
?>

会在3秒后执行跳转

<?php 
    sleep(3); 
    header("location:url地址")
?>

(学习视频分享:php视频教程

调用了sleep()方法,效果也是x秒后执行跳转

在js脚本代码中实现

1.window.location.href方法

<script type="text/javascript">
  window.location.href="helloworld.php"          
</script>

使用js方法实现延迟跳转

<script type="text/javascript">
  setTimeout("window.location.href=&#39;helloworld.php&#39;",3000);</script>

2.window.location.assign方法  延迟跳转方法同上

<script type="text/javascript">window.location.assign("helloworld.php");</script>

3.window.location.replace方法  (让新页面替换掉当前页面,不会保存在历史记录里,所有不能使用浏览器后退到原页面了)

<script type="text/javascript">
  window.location.replace("helloworld.php");</script>

4.window.open方法 三个参数,第一个URL地址。第二个打开新页面方式(比如新页面_blank,_new,自身跳转_self),第三个是新页面的方式,包括样式,位置等。

<script type="text/javascript">
  window.open("index.php",_blank,width=300px);</script>

使用HTML脚本代码完成跳转

标签里执行代码

直接插入这句代码就可以

<meta http-equiv="refresh" content="3;url=&#39;helloworld.php&#39;">

相关推荐:php教程

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。