Discuz教程网

js实现iframe的自动刷新

[复制链接]
authicon 诸葛晓明 发表于 2011-3-26 22:24:14 | 显示全部楼层 |阅读模式
  1. 简单框架

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




上一篇:IE6显示iframe页面空白的解决办法
下一篇:discuz X增强论坛编辑器,在帖子添加FLASH音乐播放器
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 07:11

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表