I have an iframe on my page where you can checkout my latest web development pages, and so on. Is it possible to refresh it with regular JavaScript or jQuery?
<iframe src="projektit" style="width:100%; height:400px; border:none;" id="iframe"></iframe>
I'm thinking about something like this.
$.ajax({
url: "../",
success: function (data) {
$("#iframe").html(data);
}
});
Any ideas?
fabian
82.9k12 gold badges99 silver badges124 bronze badges
asked Aug 25, 2012 at 16:52
user1537415
2 Answers 2
<iframe id="homepage" frameborder="1" width="400" height="300" src="http://jbcurtin.com/"></frame>
<script>
var frame=$("#homepage")
frame.attr('src',frame.attr('src'))
// None jquery:
var frame=document.getElementById('homepage')
frame.src=frame.src;
</script>
answered Aug 25, 2012 at 17:32
jbcurtin
1,8132 gold badges15 silver badges23 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Rohit Parte
This worked for me! frame.src=frame.src; bind the latest url to the iframe
To refresh an iframe I would suggest just changing the src value.
Changing the src value will trigger the iframe to refresh.
$('#iframe').prop('src', url);
If you notice it's not refreshing, you could always attach a bogus query string value to the end of the url in the case of it being cached.
var q = new Date(); // use current date obj as query string value
$('#iframe').prop('src', url + '?q=' + q.getTime());
answered Aug 25, 2012 at 16:53
Gabe
50.6k29 gold badges147 silver badges182 bronze badges
5 Comments
Gabe
@ChristianNikkanen Google is not allowing you to use them as an iframe source. Here is a working example: jsfiddle.net/XG3Ea
Gabe
@ChristianNikkanen Perhaps you could use fiddler to see what requests are being made
lang-js
<meta>tag or a simplewindow.setTimeoutsetup... but can understand if you want the iframe to be refreshed externally. Edit unless I've misunderstood what you are trying to do