一、js方式的頁面跳轉
1.window.location.href方式
<script language="JavaScript" type="text/javascript">
window.location.href="http://www.dayanmei.com/";
</script>
2.window.navigate方式跳轉 Firefox不支持
<script language="javascript">
window.navigate("top.jsp");
</script>
如果:top.jsp中有Iframe則,top.jsp在iframe中打開。(IE6測試過);
3.window.loction.replace方式實現頁面跳轉,注意跟第一種方式的區別
<script language="javascript">
window.location.replace("http://www.dayanmei.com");
</script>
有3個jsp頁面(a.jsp, b.jsp, c.jsp),進系統默認的是a.jsp ,當我進入b.jsp的時候, b.jsp里面用window.location.replace("c.jsp");與用window.location.href ="c.jsp";從用戶界面來看是沒有什么區別的,但是當c.jsp頁面有一個"返回"按鈕,調用window.history.Go(-1); wondow.history.back();方法的時候,一點這個返回按鈕就要返回b.jsp頁面的話,區別就出來了,當用 window.location.replace("c.jsp");連到c.jsp頁面的話,c.jsp頁面中的調用 window.history.go(-1);wondow.history.back();方法是不好用的,會返回到a.jsp 。
4.self.location方式實現頁面跳轉,和下面的top.location有小小區別
<script language="JavaScript">
self.location='top.htm';
</script>
5.top.location
<script language="javascript">
top.location='xx.jsp';
</script>
6.不推薦這種方式跳轉
<script language="javascript">
window.history.back(-1);
</script>
7..頁面自動刷新:把如下代碼加入<head>區域中 <meta http-equiv="refresh" content="20"> 其中20指每隔20秒刷新一次頁面.
8.<a href="javascript:history.go(-1)">返回上一步</a>
9.<a href="<%=Request.ServerVariables("HTTP_REFERER")%>">返回上一步</a>
10.<a href="javascript:" onClick="window.open('http://hi.baidu.com/630270730','','height=500,width=611,scrollbars=yes,status=yes')">打開新窗口</a>
11..window.history.forward()返回下一頁
4. window.history.go(返回第幾頁,也可以使用訪問過的URL)
二、iframe中頁面跳轉
1.iframe頁面跳轉:
"window.location.href"、"location.href"是本頁面跳轉
"parent.location.href"是上一層頁面跳轉
"top.location.href"是最外層的頁面跳轉
例:如果A,B,C,D都是jsp,D是C的iframe,C是B的iframe,B是A的iframe,如果D中js這樣寫
"window.location.href"、"location.href":D頁面跳轉
"parent.location.href":C頁面跳轉
"top.location.href":A頁面跳轉
2.iframe中的target
如果D頁面中有form的話, form提交后D頁面跳轉
<form target="_blank">: form提交后彈出新頁面
<form target="_parent">: form提交后C頁面跳轉
<form target="_top"> : form提交后A頁面跳轉
三.iframe頁面刷新
D 頁面中這樣寫:"parent.location.reload();": C頁面刷新
(當然,也可以使用子窗口的 opener 對象來獲得父窗口的對象:window.opener.document.location.reload(); )
"top.location.reload();": A頁面刷新
window.location.href = window.location.href 也可以實現頁面刷新,它與reload的區別是:如果在reload之前想服務器提交過數據,那么執行reload會重新執行這個提交操作。 而window.location.href = window.location.href 則不會,因為它是重新進入頁面。
//子窗口刷新父窗口
<script language=JavaScript>
self.opener.location.reload();
</script>
(或<a href="javascript:opener.location.reload()">刷新</a> )
//如何刷新另一個框架的頁面用
<script language=JavaScript>
parent.另一FrameID.location.reload();
</script>