阿贾克斯刷新的iframe [英] Ajax Reload iframe
本文介绍了阿贾克斯刷新的iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何才能重新加载IFRAME使用jQuery?
< HTML>
< HEAD>
<脚本类型=文/ JavaScript的SRC =jQuery的-1.4.2.js> < / SCRIPT>
<脚本类型=文/ JavaScript的>
//刷新的Iframe功能
< / SCRIPT>
< /头>
<身体GT;
< IFRAME名=F1ID =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"宽度= 500px的高度= 250像素>
< / IFRAME>
<按钮的onClick =ABC()>刷新< /按钮>
< /身体GT;
< / HTML>
解决方案
根据您的评论,以哈伊姆的帖子,你想要什么可以简化为:
$('#重装)。点击(函数(){
$('#F1')ATTR('src'中,$('#F1')ATTR(SRC)。)。
返回false;
});
或
$('#重装)。点击(函数(){
$('#F1')[0] .contentWindow.location.reload(真正的);
返回false;
});
但也许他的回答更适合您的需求。
更新:
我把一个工作示例用我上面提供的方法。我有一个< IFRAME>
在一个页面,该页面显示,打印时间的另一个页面
的< IFRAME>
HTML (为time.html):
< HTML>
< HEAD>
<脚本类型=文/ JavaScript的SRC =http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js>< / SCRIPT>
< /头>
<身体GT;
现在是时候<跨度ID =时间>< / SPAN取代。
<脚本类型=文/ JavaScript的>
$(文件)。就绪(函数(){
$('#时间)HTML(。(新的日期())的toString());
});
< / SCRIPT>
< /身体GT;
与父页面的HTML (test.html的):
< HTML>
< HEAD>
<脚本类型=文/ JavaScript的SRC =http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js>< / SCRIPT>
< /头>
<身体GT;
< IFRAME ID =框架SRC =文件:/// D:/Users/Cory/Desktop/time.htmlWIDTH =500HEIGHT =250>< / IFRAME>
<按钮ID =刷新>刷新< /按钮>
<脚本类型=文/ JavaScript的>
$(文件)。就绪(函数(){
$('#重装)。点击(函数(){
$('#框架)ATTR('src'中,$('#框架)ATTR(SRC)。)。
返回false;
});
});
< / SCRIPT>
< /身体GT;
这在Firefox 3.6和IE 7。工作得很好,我
How can I reload iframe using jquery?
<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>
解决方案
Based on your comment to Haim's post, what you want could be simplified as:
$('#reload').click(function() {
$('#f1').attr('src', $('#f1').attr('src'));
return false;
});
Or
$('#reload').click(function() {
$('#f1')[0].contentWindow.location.reload(true);
return false;
});
But perhaps his answers better suits your needs.
UPDATE:
I put together a working example using the method I provided above. I have an <iframe>
in one page that shows another page that prints the time.
The <iframe>
HTML (time.html):
<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>
And the parent page HTML (test.html):
<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>
This works just fine for me in Firefox 3.6 and IE 7.
这篇关于阿贾克斯刷新的iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文