PHP中實現頁面跳轉的方式(php跳轉,js跳轉,html跳轉)

PHP中實現頁面跳轉有以下幾種方式

在PHP腳本代碼中實現

header('location:main.php');

 

延遲跳轉(比如登陸成功後會有幾秒鐘等待時間,然後跳轉到了其他頁面)

header('Refresh:3;url=main.php');

或者

sleep(3);
header('location:main.php');

 

在js腳本代碼中實現

1.window.location.href方法

<script>
    window.location.href = 'main.php';
</script>

使用js方法實現延遲跳轉

<script>
    setTimeout("window.location.href = 'main.php'",3000);
</script>

2.window.location.assign方法 延遲跳轉方法同上

<script>
    window.location.assign = 'main.php';
</script>

4.window.open方法 三個參數,第一個URL地址。第二個打開新頁面方式(比如新頁面_blank,_new,自身跳轉_self),第三個是新頁面的方式,包括樣式,位置等。

<script>
    window.open('main.php','_blank','width=200px');
</script>

(如果被瀏覽器攔截,改爲允許即可)

 

使用HTML腳本代碼完成跳轉

在<head>標籤裏執行代碼,直接插入這句代碼就可以

<html>
<head>
    <meta http-equiv="refresh" content="3;url='main.php'">
</head>
</html>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章