亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

window.location.href的用法(動(dòng)態(tài)輸出跳轉(zhuǎn))

 更新時(shí)間:2014年08月09日 12:16:37   投稿:mdxy-dxy  
無論在靜態(tài)頁面還是動(dòng)態(tài)輸出頁面中window.location.href都是不錯(cuò)的用了跳轉(zhuǎn)的實(shí)現(xiàn)方案

javascript中的location.href有很多種用法,主要如下。

self.location.href="/url" 當(dāng)前頁面打開URL頁面
location.href="/url" 當(dāng)前頁面打開URL頁面
windows.location.href="/url" 當(dāng)前頁面打開URL頁面,前面三個(gè)用法相同。
this.location.href="/url" 當(dāng)前頁面打開URL頁面
parent.location.href="/url" 在父頁面打開新頁面
top.location.href="/url" 在頂層頁面打開新頁面

如果頁面中自定義了frame,那么可將parent self top換為自定義frame的名稱,效果是在frame窗口打開url地址

此外,window.location.href=window.location.href;和window.location.Reload()和都是刷新當(dāng)前頁面。區(qū)別在于是否有提交數(shù)據(jù)。當(dāng)有提交數(shù)據(jù)時(shí),window.location.Reload()會(huì)提示是否提交,window.location.href=window.location.href;則是向指定的url提交數(shù)據(jù)

在寫ASP.Net程序的時(shí)候,我們經(jīng)常遇到跳轉(zhuǎn)頁面的問題,我們經(jīng)常使用Response.Redirect 做ASP.NET框架頁跳轉(zhuǎn),如果客戶要在跳轉(zhuǎn)的時(shí)候使用提示,這個(gè)就不靈光了,如:

復(fù)制代碼 代碼如下:

Response.Write("< script>alert('恭喜您,注冊(cè)成功!');< /script>"); 
Response.Redirect("main.html");  

這時(shí)候我們的提示內(nèi)容沒有出來就跳轉(zhuǎn)了,和Response.Redirect("main.html");沒有任何區(qū)別。

這時(shí)我們采用下面代碼試驗(yàn)一下:

ASP.NET框架頁跳轉(zhuǎn)的另一實(shí)現(xiàn)

復(fù)制代碼 代碼如下:

Response.Write("< script language=javascript>alert('恭喜您,注冊(cè)成功!')< /script>"); 
Response.Write("< script language=javascript>window.location.href='main.html'< /script>");

這個(gè)即實(shí)現(xiàn)了我們的要求,在提示后,跳轉(zhuǎn)頁面。

最重要的是window.location.href 語句可以實(shí)現(xiàn)一個(gè)框架的頁面在執(zhí)行服務(wù)器端代碼后刷新另一個(gè)框架的頁面(Response.Redirect無法達(dá)到,至少我沒有發(fā)現(xiàn)):

如:index.htm頁面中有二個(gè)框架,分別為 frameLeft和frameRight,在frameRight頁面中執(zhí)行服務(wù)器端代碼后刷新frameLeft中的頁面。

先前最常見的是注冊(cè)之后,自動(dòng)刷新登陸框,讓登陸框換成已登陸頁面,只要在注冊(cè)成功的代碼之后加上一段,即可以實(shí)現(xiàn)刷新另個(gè)框架的頁面。代碼如下:

復(fù)制代碼 代碼如下:

Response.Write("< script language=javascript>alert('恭喜您,注冊(cè)成功!')< /script>"); 
Response.Write("< script language=javascript>window.parent.frameLeft.location.href='main.html'< /script>");  

這樣就搞定了ASP.NET框架頁跳轉(zhuǎn)中斷的問題。其實(shí)asp、php中一般都使用這種方式。


"window.location.href"、"location.href"是本頁面跳轉(zhuǎn)
"parent.location.href"是上一層頁面跳轉(zhuǎn)
"top.location.href"是最外層的頁面跳轉(zhuǎn)

舉例說明:

如果A,B,C,D都是jsp,D是C的iframe,C是B的iframe,B是A的iframe,如果D中js這樣寫

"window.location.href"、"location.href":D頁面跳轉(zhuǎn)
"parent.location.href":C頁面跳轉(zhuǎn)
"top.location.href":A頁面跳轉(zhuǎn)

如果D頁面中有form的話,

<form>: form提交后D頁面跳轉(zhuǎn)
<form target="_blank">: form提交后彈出新頁面
<form target="_parent">: form提交后C頁面跳轉(zhuǎn)
<form target="_top"> : form提交后A頁面跳轉(zhuǎn)
 
關(guān)于頁面刷新,D 頁面中這樣寫:

"parent.location.reload();": C頁面刷新 (當(dāng)然,也可以使用子窗口的 opener 對(duì)象來獲得父窗口的對(duì)象:window.opener.document.location.reload(); )

"top.location.reload();": A頁面刷新

相關(guān)文章

最新評(píng)論