How can I reload iframe using jquery?
//Reload Iframe Function
Reload
Thanks in Advance
How can I reload iframe using jquery?
//Reload Iframe Function
Reload
Thanks in Advance
$("#reload").click(function() {
jQuery.each($("iframe"), function() {
$(this).attr({
src: $(this).attr("src")
});
});
return false;
});
This will loop through each iFrame every time you click on a link with a class of reloadAds and set the source of the iFrame to itself
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 Larson/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.