親測,not復制粘貼
PHP中實現頁面跳轉有一下幾種方式,看了幾個人寫的不是很條理,自己整理一下
在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地址")?> 調用了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='helloworld.php'",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腳本代碼完成跳轉
在<head>標簽里執行代碼
直接插入這句代碼就可以
<meta http-equiv="refresh" content="3;url='helloworld.php'">