《PHP實(shí)例:用HTML/JS/PHP方式實(shí)現(xiàn)頁面延時(shí)跳轉(zhuǎn)的簡單實(shí)例》要點(diǎn):
本文介紹了PHP實(shí)例:用HTML/JS/PHP方式實(shí)現(xiàn)頁面延時(shí)跳轉(zhuǎn)的簡單實(shí)例,希望對(duì)您有用。如果有疑問,可以聯(lián)系我們。
WEB開發(fā)中經(jīng)常會(huì)遇到頁面跳轉(zhuǎn)或延時(shí)跳轉(zhuǎn)的需求,掌握各種頁面跳轉(zhuǎn)方式非常必要.PHP應(yīng)用
以下是我總結(jié)有用HTML/JS/PHP三類方式實(shí)現(xiàn)跳轉(zhuǎn)的方法,例子皆為三秒后跳轉(zhuǎn)到index.php頁面.PHP應(yīng)用
1,HTML方法:PHP應(yīng)用
在HEAD中添加<meta>標(biāo)簽PHP應(yīng)用
<meta http-equiv=”refresh” content=”3;url='index.php'” >
2,JS控制跳轉(zhuǎn)方法PHP應(yīng)用
A.Location直接加鏈接方式PHP應(yīng)用
<script type="text/javascript"> setTimeout("window.location=('index.php'",3000); </script>
B.Location.href方式PHP應(yīng)用
<script type="text/javascript"> setTimeout("window.location.href='index.php'",3000); </script>
C.Location.assign方式PHP應(yīng)用
<script type="text/javascript"> setTimeout("window.location.assign('index.php')",3000); </script>
D.Location.replace方式(注意頁面是被“替換”掉了,不會(huì)在瀏覽器的歷史記錄被查詢到)PHP應(yīng)用
<script type="text/javascript"> Widdow.location.replace(‘index.php'); </script>
E.JS歷史記錄go(n)方式(n表示對(duì)歷史記錄相對(duì)當(dāng)前頁的前進(jìn)步數(shù),n為負(fù)數(shù)表示返回以前的頁面)PHP應(yīng)用
<script type="text/javascript"> window.history.go(n); </script>
F.JS歷史記錄go(url)方式(注意url必須是歷史記錄內(nèi)的,不然頁面不會(huì)進(jìn)行跳轉(zhuǎn))PHP應(yīng)用
<script type="text/javascript"> window.history.go(‘index.php'); </script>
G.JS?window.open方式,通過打開一個(gè)新窗口,實(shí)現(xiàn)跳轉(zhuǎn).(其第二個(gè)屬性為可選目標(biāo)選項(xiàng),值可以是frame?id/_blank等,第三個(gè)選項(xiàng)為新彈出窗口的具體設(shè)置選項(xiàng),包括height/width等)PHP應(yīng)用
<script type="text/javascript"> setTimeout("window.open('index.php',target,args)",3000); </script>
3,PHP腳本控制跳轉(zhuǎn)方式,通過改寫HTTP頭信息來進(jìn)行跳轉(zhuǎn)PHP應(yīng)用
A.header refresh方式:PHP應(yīng)用
Header(“refresh:3;url='index.php'”);
B.?header?location?方式?:PHP應(yīng)用
sleep(3); Header(“l(fā)ocation:index.php”);
要注意這種方式會(huì)導(dǎo)致無法進(jìn)入當(dāng)前頁面.即若當(dāng)前在register.php頁面鏈接到login.php頁面時(shí),login.php頁面內(nèi)用header?location方式跳轉(zhuǎn),頁面會(huì)從register.php頁面直接等待三秒跳轉(zhuǎn)到index.php,不會(huì)進(jìn)入到login.php頁面,這是因?yàn)?/span>header?location會(huì)對(duì)頁面進(jìn)行重定向.PHP應(yīng)用
如有錯(cuò)誤,歡迎指正,謝謝.PHP應(yīng)用
以上這篇用HTML/JS/PHP方式實(shí)現(xiàn)頁面延時(shí)跳轉(zhuǎn)的簡單實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持維易PHP.PHP應(yīng)用
轉(zhuǎn)載請(qǐng)注明本頁網(wǎng)址:
http://www.snjht.com/jiaocheng/5634.html