zoukankan      html  css  js  c++  java
  • 用Javascript刷新框架子页面的七种方法

    下面以三个页面分别命名为framedemo.html,top.html,button.html为例来具体说明如何做。

    其中framedemo.html由上下两个页面组成,代码如下:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> frameDemo </TITLE>
    </HEAD>
    <frameset rows="50%,50%">
    <frame name=top src="top.html">
    <frame name=button src="button.html">
    </frameset>
    </HTML>

     现在假设top.html即上面的页面有一个button来实现对下面页面的刷新,可以用以下七种语句,哪个好用自己看着办了。

      语句1. window.parent.frames[1].location.reload();

      语句2. window.parent.frames.bottom.location.reload();

      语句3. window.parent.frames["bottom"].location.reload();

      语句4. window.parent.frames.item(1).location.reload();

      语句5. window.parent.frames.item('bottom').location.reload();

      语句6. window.parent.bottom.location.reload();

      语句7. window.parent['bottom'].location.reload();

      解释一下:

      1.window指代的是当前页面,例如对于此例它指的是top.html页面。

      2.parent指的是当前页面的父页面,也就是包含它的框架页面。例如对于此例它指的是framedemo.html。

      3.frames是window对象,是一个数组。代表着该框架内所有子页面。

      4.item是方法。返回数组里面的元素。

      5.如果子页面也是个框架页面,里面还是其它的子页面,那么上面的有些方法可能不行。
      top.html源代码;(页面上有七个按钮,功能都是刷新下面的框架页面)

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    </HEAD>
    <BODY>
    <input type=button value="刷新1" onclick="window.parent.frames[1].location.reload()"><br>
    <input type=button value="刷新2" onclick="window.parent.frames.bottom.location.reload()"><br>
    <input type=button value="刷新3" onclick="window.parent.frames['bottom'].location.reload()"><br>
    <input type=button value="刷新4" onclick="window.parent.frames.item(1).location.reload()"><br>
    <input type=button value="刷新5" onclick="window.parent.frames.item('bottom').location.reload()"><br>
    <input type=button value="刷新6" onclick="window.parent.bottom.location.reload()"><br>
    <input type=button value="刷新7" onclick="window.parent['bottom'].location.reload()"><br>
    </BODY>
    </HTML>

    下面是bottom.html页面源代码,为了证明下方页面的确被刷新了,在装载完页面弹出一个对话框。

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    </HEAD>
    <BODY onload="alert('我被加载了!')">
    <h1>This is the content in button.html.</h1>
    </BODY>
    </HTML>

  • 相关阅读:
    tomcat 启动 报错Neither the JAVA_HOME nor the JRE_HOME environment variable is definedtemp
    tomcat linux 加入服务自动启动
    registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
    tomcat 8 加 struts2的 java.lang.NoSuchFieldException: resourceEntries
    tomcat Can't create cache file!
    tomcat 部署时修改服务器时间
    tomcat java变量环境设置
    scrapy 动态IP、随机UA、验证码
    scrapy xpath、正则表达式、css选择器
    Saltstack windows可视化操作(十四)
  • 原文地址:https://www.cnblogs.com/top5/p/1618883.html
Copyright © 2011-2022 走看看