分享數(shù):12JavaScript自動刷新頁面;使用JavaScript location.reload方法刷新網(wǎng)頁。當(dāng)用戶點擊一個鏈接此代碼可以自動在一個事件調(diào)用。如果想使用鼠標(biāo)點擊刷新網(wǎng)頁,可以用下面的代碼:
<a href="javascript:location.reload(true)">Refresh Page</a>

要了解它更好的辦法,可以刷新頁面自動刷新:還可以使用JavaScript后自動給定時間段,以刷新頁面。以下是每5秒后會刷新此頁面的例子。可以改變這個時候按您的要求。<html><head><script type="text/JavaScript"><!--function AutoRefresh( t ) { setTimeout("location.reload(true);", t);}// --></script></head><body><p>This page will refresh every 5 seconds.</p></body></html>這里的 setTimeout()是一個內(nèi)置的JavaScript函數(shù),可用于給定的時間間隔之后執(zhí)行另一個函數(shù)。 javascript 強(qiáng)制刷新頁面的實現(xiàn)代碼Javascript刷新頁面的幾種方法: 1 history.go(0) 2 location.reload() 3 location=location 4 location.assign(location) 5 document.execCommand('Refresh') 6 window.navigate(location) 7 location.replace(location) 8 document.URL=location.href 自動刷新頁面的方法: 1.頁面自動刷新:把如下代碼加入<head>區(qū)域中 <meta http-equiv="refresh" content="20"> 其中20指每隔20秒刷新一次頁面. 2.頁面自動跳轉(zhuǎn):把如下代碼加入<head>區(qū)域中 <meta http-equiv="refresh" content="20;url=http://www.jb51.net"> 其中20指隔20秒后跳轉(zhuǎn)到http://www.jb51.net頁面 3.頁面自動刷新js版 代碼如下:<script language="JavaScript"> function myrefresh() { window.location.reload(); } setTimeout('myrefresh()',1000); //指定1秒刷新一次 </script> ASP.NET如何輸出刷新父窗口腳本語句 1. this.response.write("<script>opener.location.reload();</script>"); 2. this.response.write("<script>opener.window.location.href = opener.window.location.href;</script>"); 3. Response.Write("<script language=javascript>opener.window.navigate(''你要刷新的頁.asp'');</script>")JS刷新框架的腳本語句 //如何刷新包含該框架的頁面用 <script language=JavaScript> parent.location.reload(); </script> //子窗口刷新父窗口 <script language=JavaScript> self.opener.location.reload(); </script> ( 或 <a href="javascript:opener.location.reload()">刷新</a> ) //如何刷新另一個框架的頁面用 <script language=JavaScript> parent.另一FrameID.location.reload(); </script> 如果想關(guān)閉窗口時刷新或者想開窗時刷新的話,在<body>中調(diào)用以下語句即可。 <body> 開窗時刷新 <body onUnload="opener.location.reload()"> 關(guān)閉時刷新 <script language="javascript"> window.opener.document.location.reload() </script> //跳出頁面 <SCRIPT LANGUAGE=JAVASCRIPT> <!-- if (top.location !== self.location) { top.location=self.location; } javascript 頁面只自動刷新一次代碼如下:<Script> function reurl(){ url = location.href; //把當(dāng)前頁面的地址賦給變量 url var times = url.split("?"); //分切變量 url 分隔符號為 "?" if(times[1] != 1){ //如果?后的值不等于1表示沒有刷新 url += "?1"; //把變量 url 的值加入 ?1 self.location.replace(url); //刷新頁面 } } onload=reurl </script> 
其他頁面刷新的方式;1.onResume()方法 activity或fragment頁面中(簡稱原頁面)啟動新的頁面(簡稱新頁面),新頁面返回時需要原頁面刷新數(shù)據(jù),觀察他們的生命周期可以看出,啟動新的頁面,原頁面會依次調(diào)用onPause(), and onStop()方法,當(dāng)新的頁面關(guān)閉返回時,原頁面會調(diào)用onStart(),onResume(),因此把加載數(shù)據(jù)放到onResume()方法中即可 @Override public void onResume() { super.onResume(); getData();//加載數(shù)據(jù) }.startActivityForResult方法三種情況a.用新頁面關(guān)閉的默認(rèn)碼,原頁面就刷新設(shè)置返回碼private int requestCode = 0X5;//返回碼大于零啟動新頁面startActivityForResult(new Intent(context,NewActivity.class).putExtras(bundle), requestCode);//攜帶bundle啟動新頁面新頁面關(guān)閉時會自動調(diào)用Activity.RESULT_CANCELED,不需要在新頁面寫結(jié)果碼代碼原頁面刷新數(shù)據(jù): @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub if (requestCode == this.requestCode && resultCode == Activity.RESULT_CANCELED) { //刷新數(shù)據(jù) }b.改寫新頁面關(guān)閉時的默認(rèn)碼,原頁面刷新設(shè)置結(jié)果碼為RESULT_OK覆寫finish( )方法 @Override public void finish() { setResult(RESULT_OK); super.finish(); }原頁面刷新數(shù)據(jù): @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub if (requestCode == this.requestCode && resultCode == Activity.RESULT_OK) { //加載數(shù)據(jù) } }c.新頁面有特定操作,比如提交數(shù)據(jù),原頁面才刷新數(shù)據(jù)可以在新頁面設(shè)置requestCode,這也是最通用的方法,不 累述3.其他方法接口回調(diào),廣播,觀察者模式 .net頁面刷新的方式;第一:private void Button1_Click( object sender, System.EventArgs e ) { Response.Redirect( Request.Url.ToString( ) );}第二:private void Button2_Click( object sender, System.EventArgs e ) { Response.Write( " <script language=javascript>window.location.href=document.URL; </script>" );}第三:private void Button3_Click( object sender, System.EventArgs e ) { Response.AddHeader( "Refresh","0" );}第四:private void Button6_Click( object sender, System.EventArgs e ) { //好像有些不對? //Response.Write( " <script language=javascript>window.location.reload( ); </script>" );}第五:(需替換<>)<script><!--var limit="3:00"if ( document.images ){ var parselimit=limit.split( ":" )parselimit=parselimit[0]*60+parselimit[1]*1}function beginrefresh( ){ if ( !document.images )returnif ( parselimit==1 )window.location.reload( )else { parselimit-=1curmin=Math.floor( parselimit/60 )cursec=parselimit%60if ( curmin!=0 )curtime=curmin+"分"+cursec+"秒后重刷本頁!"elsecurtime=cursec+"秒后重刷本頁!"window.status=curtimesetTimeout( "beginrefresh( )",1000 ) }}window.onload=beginrefresh//--> </script><DIVfont-size:14px;">LEFT: 408px;POSITION: absolute;TOP: 232px" ms_positioning="text2D"><P><FONT size="3">自動刷新頁面</FONT></P></DIV>第六:<meta http-equiv="refresh" content="300;url=target.html">用window.location.href實現(xiàn)刷新另個框架頁面在寫ASP.Net程序的時候,我們經(jīng)常遇到跳轉(zhuǎn)頁面的問題,我們經(jīng)常使用Response.Redirect ,如果客戶要在跳轉(zhuǎn)的時候使用提示,這個就不靈光了,如:Response.Write("<script>alert('恭喜您,注冊成功!');</script>");Response.Redirect("main.html");這時候我們的提示內(nèi)容沒有出來就跳轉(zhuǎn)了,和Response.Redirect("main.html");沒有任何區(qū)別。這時我們采用下面代碼試驗一下:Response.Write("<script language=javascript>alert('恭喜您,注冊成功!')</script>");Response.Write("<script language=javascript>window.location.href='main.html'</script>");這個即實現(xiàn)了我們的要求,在提示后,跳轉(zhuǎn)頁面。最重要的是window.location.href 語句可以實現(xiàn)一個框架的頁面在執(zhí)行服務(wù)器端代碼后刷新另一個框架的頁面(Response.Redirect無法達(dá)到,至少我沒有發(fā)現(xiàn)):如:index.htm頁面中有二個框架,分別為 frameLeft和frameRight,在frameRight頁面中執(zhí)行服務(wù)器端代碼后刷新frameLeft中的頁面。先前最常見的是注冊之后,自動刷新登陸框,讓登陸框換成已登陸頁面,只要在注冊成功的代碼之后加上一段,即可以實現(xiàn)刷新另個框架的頁面。代碼如下:Response.Write("<script language=javascript>alert('恭喜您,注冊成功!')</script>");Response.Write("<script language=javascript>window.parent.frameLeft.location.href='main.html'</script>");自動刷新頁面的實現(xiàn)方法總結(jié):1)<meta http-equiv="refresh"content="10;url=跳轉(zhuǎn)的頁面">10表示間隔10秒刷新一次2)<script language=''javascript''>window.location.reload(true);</script>如果是你要刷新某一個iframe就把window給換成frame的名字或ID號3)<script language=''javascript''>window.navigate("本頁面url");</script>4>function abc(){window.location.href="/blog/window.location.href";setTimeout("abc()",10000);}刷新本頁:Response.Write("<script language=javascript>window.location.href=window.location.href;</script>")刷新父頁:Response.Write("<script language=javascript>opener.location.href=opener.location.href;</script>")轉(zhuǎn)到指定頁:Response.Write("<script language=javascript>window.location.href='yourpage.aspx';</script>")刷新頁面實現(xiàn)方式總結(jié)(HTML,ASP,JS)'by aloxy定時刷新:1,<script>setTimeout("location.href='url'",2000)</script>說明:url是要刷新的頁面URL地址2000是等待時間=2秒,2,<meta content="n;url">說明:n is the number of seconds to wait before loading the specified URL.url is an absolute URL to be loaded.n,是等待的時間,以秒為單位url是要刷新的頁面URL地址3,<%response.redirect url%>說明:一般用一個url參數(shù)或者表單傳值判斷是否發(fā)生某個操作,然后利用response.redirect 刷新。4,刷新框架頁 〈script language=javascript>top.leftFrm.location.reload();parent.frmTop.location.reload();</script〉彈出窗體后再刷新的問題Response.Write("<script>window.showModalDialog('../OA/SPCL.aspx',window,'dialogHeight: 300px; dialogWidth: 427px; dialogTop: 200px; dialogLeft: 133px')</script>");//open Response.Write("<script>document.location=document.location;</script>");在子窗體頁面代碼head中加入<base target="_self"/>刷新的內(nèi)容加在 if (!IsPostBack) 中在框架頁中右面刷新左面 //刷新框架頁左半部分 Response.Write("<script language=javascript>"); Response.Write("parent.left.location.href='PayDetailManage_Left.aspx'"); Response.Write("</script>");頁面定時刷新功能實現(xiàn)有三種方法:1,在html中設(shè)置:<title>xxxxx</title>之後加入下面這一行即可!定時刷新:<META HTTP-EQUIV="Refresh" content="10">10代表刷新間隔,單位為秒2.jsp<% response.setHeader("refresh","1"); %>每一秒刷新一次3.使用javascript:<script language="javascript">setTimeout("self.location.reload();",1000);<script>一秒一次頁面自動跳轉(zhuǎn):在html中設(shè)置:<title>xxxxx</title>之後加入下面這一行即可!定時跳轉(zhuǎn)并刷新:<meta http-equiv="refresh" content="20;url=http://自己的URL">,其中20指隔20秒后跳轉(zhuǎn)到http://自己的URL 頁面。TAG標(biāo)簽耗時:0.046237945556641 秒
如沒特殊注明,文章均為江浙滬網(wǎng)絡(luò)推廣,轉(zhuǎn)載請注明來自http://www.0898bike.com/html/news/