首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ajax Reload iframe

Ajax Reload iframe
EN

Stack Overflow用户
提问于 2010-08-24 11:37:05
回答 1查看 28.8K关注 0票数 8

如何使用jquery重新加载iframe?

代码语言:javascript
复制
<html>

<head>
<script type="text/javascript" src="jquery-1.4.2.js" > </script>


<script type="text/javascript">
//Reload Iframe Function    
</script>

</head>

<body>
    <iframe name="f1" id = "f1" src="http://www.google.com.pk/search?q=usa+current+time&ie=utf-8&oe=utf-8&aq=t&client=firefox-a&rlz=1R1GGLL_en" width=500px height=250px>
    </iframe>

<button onClick="abc()"> Reload </button>

</body>

</html>
EN

回答 1

Stack Overflow用户

发布于 2010-08-24 11:51:33

根据您对Haim帖子的评论,您想要的内容可以简化为:

代码语言:javascript
复制
$('#reload').click(function() {
    $('#f1').attr('src', $('#f1').attr('src'));
    return false;
});

代码语言:javascript
复制
$('#reload').click(function() {
    $('#f1')[0].contentWindow.location.reload(true);
    return false;
});

但也许他的答案更适合你的需要。

更新:

我使用上面提供的方法编写了一个工作示例。我在一个页面中有一个<iframe>,它显示了另一个打印时间的页面。

<iframe> HTML (time.html):

代码语言:javascript
复制
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<body>

    The time is now <span id="time"></span>.

    <script type="text/javascript">

        $(document).ready(function() {
            $('#time').html((new Date()).toString());
        });

    </script>
</body>

和父页面HTML (test.html):

代码语言:javascript
复制
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<body>

    <iframe id="frame" src="file:///D:/Users/Cory/Desktop/time.html" width="500" height="250"></iframe>

    <button id="reload">Refresh</button>

    <script type="text/javascript">

        $(document).ready(function() {
            $('#reload').click(function() {
                $('#frame').attr('src', $('#frame').attr('src'));
                return false;
            });
        });

    </script>
</body>

在Firefox3.6和IE7中,这对我来说很好。

票数 13
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3555984

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档