jquery实现局部刷新Iframe

1,reload 方法,该方法强迫浏览器刷新当前页面。

  语法:location.reload([bForceGet])

  参数: bForceGet, 可选参数, 默认为 false,从客户端缓存里取当前页。true, 则以 GET 方式,从服务端取最新的页面, 相当于客户端点击 F5("刷新")

1

2

3

<script language="JavaScript">

window.location.reload();

</script>

1

2

3

4

5

6

7

//方法1

document.getElementById('FrameID').contentWindow.location.reload(true);

//方法2

document.getElementById('youriframe').src=src;

实例:

1

2

3

4

5

6

7

8

9

10

<iframe id="myframe" width="100%" frameBorder="0" src="test.html" scrolling="no"></iframe>

<input type="button" onclick="javascript:refreshFrame();" value="Refresh Frame" />

  

<script type="text/javascript">

<!--

function refreshFrame(){

    document.getElementById('myframe').contentWindow.location.reload(true);

}

//-->

</script>

二。jquery实现强制刷新

  $('#iframe').attr('src', $('#iframe').attr('src'));

1

2

3

4

5

6

7

8

9

10

11

12

13

//刷新包含该框架的页面用  

<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>

总结:网上一大堆document.frames('ifrmname').location.reload()已经不能用了

自己验证

页面中动态加载子窗体内容的情况,

1

2

3

$("#refresh").click(function(){

     parent.location.reload();

});

 刷新当前子窗体

            $("#refresh").click(function() {
                self.location.reload();
            });

可以工作

猜你喜欢

转载自blog.csdn.net/qq_39705793/article/details/82911329