js页面刷新总结

来源:互联网 发布:女生喜欢穿热裤 知乎 编辑:程序博客网 时间:2024/05/22 05:29
 
2009-04-27

js页面刷新总结

    博客分类:
  • JS+AJAX
2)   
  1. <script>   
  2. window.location.reload(true);   
  3. </script>   
  4. 如果是你要刷新某一个iframe就把window给换成frame的名字或ID号   
  5. 3)   
  6. <script>   
  7. window.navigate("本页面url");   
  8. </script>   
  9. 4>   
  10.   
  11. function abc()   
  12. {   
  13. window.location.href="/blog/window.location.href";   
  14. setTimeout("abc()",10000);   
  15. }   
  16.   
  17. 刷新本页:   
  18. Response.Write("<script>window.location.href=window.location.href;</script>")   
  19.   
  20. 刷新父页:   
  21. Response.Write("<script>opener.location.href=opener.location.href;</script>")   
  22.   
  23. 转到指定页:   
  24. Response.Write("<script>window.location.href='yourpage.aspx';</script>")   
  25. 刷新页面实现方式总结(HTML,ASP,JS)   
  26. 'by aloxy   
  27.   
  28. 定时刷新:   
  29. 1,<script>setTimeout("location.href='url'",2000)</script>   
  30.   
  31. 说明:url是要刷新的页面URL地址   
  32. 2000是等待时间=2秒,   
  33.   
  34. 2,   
  35.   
  36. 说明:   
  37. n is the number of seconds to wait before loading the specified URL.   
  38. url is an absolute URL to be loaded.   
  39. n,是等待的时间,以秒为单位   
  40. url是要刷新的页面URL地址   
  41.   
  42. 3,<!--sponse.redirect ur-->   
  43.   
  44. 说明:一般用一个url参数或者表单传值判断是否发生某个操作,然后利用response.redirect 刷新。   
  45.   
  46. 4,刷新框架页   
  47.    〈script language=javascript>top.leftFrm.location.reload();parent.frmTop.location.reload(); 弹出窗体后再刷新的问题   
  48.   
  49. Response.Write("<script>window.showModalDialog('../OA/SPCL.aspx',window,'dialogHeight: 300px; dialogWidth: 427px; dialogTop: 200px; dialogLeft: 133px')</script>");//open  
  50.              Response.Write("<script>document.location=document.location;</script>");   
  51.   
  52. 在子窗体页面代码head中加入   
  53.   
  54. 刷新的内容加在    if (!IsPostBack) 中   
  55.   
  56. 在框架页中右面刷新左面   
  57.     //刷新框架页左半部分   
  58.     Response.Write("<script>");   
  59.     Response.Write("parent.left.location.href='PayDetailManage_Left.aspx'");   
  60.     Response.Write("</script>");   
  61.   
  62. 页面定时刷新功能实现   
  63.   
  64. 有三种方法:   
  65. 1,在html中设置:   
  66. 之後加入下面这一行即可!   
  67. 定时刷新:   
  68. 10代表刷新间隔,单位为秒   
  69.   
  70. 2.jsp   
  71. <!--esponse.setHeader("refresh","1");-->   
  72. 每一秒刷新一次   
  73.   
  74. 3.使用javascript:   
  75. <script>   
  76. setTimeout("self.location.reload();",1000);   
  77. <script>   
  78. 一秒一次   
  79.   
  80.   
  81. 页面自动跳转:   
  82.   
  83. <script>   
  84. window.location.href="mian.aspx";   
  85. history.go(0);//window.close();   //关闭浏览器此页的窗口  
  86. </script>   
  87.   
  88. 先来看一个简单的例子:   
  89. 下面以三个页面分别命名为frame.html、top.html、bottom.html为例来具体说明如何做。   
  90.   
  91. frame.html 由上(top.html)下(bottom.html)两个页面组成,代码如下:   
  92. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">   
  93. <HTML>   
  94. <HEAD>   
  95. <TITLE> frame </TITLE>   
  96. </HEAD>   
  97. <frameset rows="50%,50%">   
  98. <frame name=top src="top.html">   
  99. <frame name=bottom src="bottom.html">   
  100. </frameset>   
  101. </HTML>   
  102. 现在假设top.html (即上面的页面) 有七个button来实现对bottom.html (即下面的页面) 的刷新,可以用以下七种语句,哪个好用自己看着办了。   
  103.   
  104. 语句1. window.parent.frames[1].location.reload();   
  105. 语句2. window.parent.frames.bottom.location.reload();   
  106. 语句3. window.parent.frames["bottom"].location.reload();   
  107. 语句4. window.parent.frames.item(1).location.reload();   
  108. 语句5. window.parent.frames.item('bottom').location.reload();   
  109. 语句6. window.parent.bottom.location.reload();   
  110. 语句7. window.parent['bottom'].location.reload();   
  111.   
  112. top.html 页面的代码如下:   
  113. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">   
  114. <HTML>   
  115. <HEAD>   
  116.   <TITLE> top.html </TITLE>   
  117. </HEAD>   
  118. <BODY>   
  119. <input type=button value="刷新1" onclick="window.parent.frames[1].location.reload()"><br>   
  120. <input type=button value="刷新2" onclick="window.parent.frames.bottom.location.reload()"><br>   
  121. <input type=button value="刷新3" onclick="window.parent.frames['bottom'].location.reload()"><br>   
  122. <input type=button value="刷新4" onclick="window.parent.frames.item(1).location.reload()"><br>   
  123. <input type=button value="刷新5" onclick="window.parent.frames.item('bottom').location.reload()"><br>   
  124. <input type=button value="刷新6" onclick="window.parent.bottom.location.reload()"><br>   
  125. <input type=button value="刷新7" onclick="window.parent['bottom'].location.reload()"><br>   
  126. </BODY>   
  127. </HTML>   
  128. 下面是bottom.html页面源代码,为了证明下方页面的确被刷新了,在装载完页面弹出一个对话框。   
  129.   
  130. bottom.html 页面的代码如下:   
  131. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">   
  132. <HTML>   
  133. <HEAD>   
  134.   <TITLE> bottom.html </TITLE>   
  135. </HEAD>   
  136. <BODY onload="alert('我被加载了!')">   
  137. <h1>This is the content in bottom.html.</h1>   
  138. </BODY>   
  139. </HTML>   
  140. 解释一下:   
  141. 1.window指代的是当前页面,例如对于此例它指的是top.html页面。   
  142. 2.parent指的是当前页面的父页面,也就是包含它的框架页面。例如对于此例它指的是framedemo.html。   
  143. 3.frames是window对象,是一个数组。代表着该框架内所有子页面。   
  144. 4.item是方法。返回数组里面的元素。   
  145. 5.如果子页面也是个框架页面,里面还是其它的子页面,那么上面的有些方法可能不行。   
  146.   
  147. 附:   
  148. Javascript刷新页面的几种方法:   
  149. 1   history.go(0)   
  150. 2   location.reload()   
  151. 3   location=location   
  152. 4   location.assign(location)   
  153. 5   document.execCommand('Refresh')   
  154. 6    window.navigate(location)   
  155. 7   location.replace(location)   
  156. 8   document.URL=location.href   
  157.   
  158. 自动刷新页面的方法:   
  159. 1.页面自动刷新:把如下代码加入<head>区域中   
  160. <meta http-equiv="refresh" content="20">   
  161. 其中20指每隔20秒刷新一次页面.   
  162.   
  163. 2.页面自动跳转:把如下代码加入<head>区域中   
  164. <meta http-equiv="refresh" content="20;url=http://www.wyxg.com">   
  165. 其中20指隔20秒后跳转到http://www.wyxg.com页面   
  166.   
  167. 3.页面自动刷新js版   
  168. <script language="JavaScript">   
  169. function myrefresh()   
  170. {   
  171.      window.location.reload();   
  172. }   
  173. setTimeout('myrefresh()',1000); //指定1秒刷新一次  
  174. </script>   
  175.   
  176. ASP.NET如何输出刷新父窗口脚本语句   
  177. 1. this.response.write("<script>opener.location.reload();</script>");   
  178.   
  179. 2. this.response.write("<script>opener.window.location.href = opener.window.location.href;</script>");     
  180.   
  181. 3. Response.Write("<script language=javascript>opener.window.navigate(''你要刷新的页.asp'');</script>")   
  182.   
  183.   
  184. JS刷新框架的脚本语句   
  185.   
  186. //如何刷新包含该框架的页面用      
  187. <script language=JavaScript>   
  188. parent.location.reload();   
  189. </script>     
  190.   
  191. //子窗口刷新父窗口   
  192. <script language=JavaScript>   
  193.    self.opener.location.reload();   
  194. </script>   
  195. ( 或 <a href="javascript:opener.location.reload()">刷新</a>   )   
  196.   
  197. //如何刷新另一个框架的页面用      
  198. <script language=JavaScript>   
  199. parent.另一FrameID.location.reload();   
  200. </script>   
  201.   
  202. 如果想关闭窗口时刷新或者想开窗时刷新的话,在<body>中调用以下语句即可。   
  203.   
  204. <body onload="opener.location.reload()"> 开窗时刷新   
  205. <body onUnload="opener.location.reload()"> 关闭时刷新   
  206.   
  207. <script language="javascript">   
  208.   
  209. 文章出处:http://www.diybl.com/course/4_webprogram/ajax/ajaxxl/2008922/144561.html  
原创粉丝点击