Reload an iframe with jQuery
If the iframe was not on a different domain, you could do something like this:
document.getElementById(FrameID).contentDocument.location.reload(true);
But since the iframe is on a different domain, you will be denied access to the iframe's contentDocument
property by the same-origin policy.
But you can hackishly force the cross-domain iframe to reload if your code is running on the iframe's parent page, by setting it's src attribute to itself. Like this:
// hackishly force iframe to reload
var iframe = document.getElementById(FrameId);
iframe.src = iframe.src;
If you are trying to reload the iframe from another iframe, you are out of luck, that is not possible.
What’s the best way to reload / refresh an iframe?
document.getElementById('some_frame_id').contentWindow.location.reload();
be careful, in Firefox, window.frames[]
cannot be indexed by id, but by name or index
How can I reload an iframe on click?
like this
document.getElementById('iframeID').contentWindow.location.reload();
or via
document.getElementById('iframeID').src = document.getElementById('iframeID').src;
Refresh an iframe by clicking on accordion tab
Put this in your click event:
$('#I1').attr('src', function (i, val) {return val;});
It basically sets the src back to itself, which causes the iframe to reload.
You can also do it in JS with:
document.getElementById('#I1').contentDocument.location.reload(true);
How To Reload A iframe Using jQuery
Sort of a HTML:
<input type="text" name="url" id="url"/>
<input type="submit" name="go" id="go" value="Go!"/>
<iframe id="miniBrowser"></iframe>
jQuery:
$('#go').on('click', function() {
$('#miniBrowser').attr('src', $('#url').val());
});
Catch iframe reload with jQuery
You are looking for the load
action of a div in your example above, not the iframe. Try:
$("#myFrame").on("load", function () {
alert("Hi there, hello");
})
Additionally, if you are not using other libraries, use $()
to access jQuery as opposed to jQuery()
Also note that any functions that you want to run on your page must be bound to jQuery's document ready event like so:
$(function () {
// your code goes here
$("#myFrame").attr("src", "http://google.com"); // <- this works
})
$("#myFrame").attr("src", "http://google.com"); // <- this does not work
Refresh current page in iframe with javascript/jquery
You can try this.
document.getElementById('iframe1').contentWindow.location.reload();
Used above line and it gives error sometime, because it is not allowed to get a property from the window from another domain.
The “Same Origin” policy limits the access of one window to another.
The reason behind that is security. If you have blabla.com in one window and gmail.com in another one, then you’d not want a script from blabla.com to access or modify your mail or run actions in context of gmail on your behalf.
You can refer http://javascript.info/tutorial/same-origin-security-policy more information.
How to refresh iframe after regular interval in html
Try this :
<script>
var src = $('#foo').attr('src');
setInterval(function () {
$('#foo').remove();
var iframe_html = '<iframe src="'+ src +'" width="100%" height="100%"></iframe>';
$('#iframe').html(iframe_html);
}, 1000);
</script>
<span id="iframe">
<iframe id="foo" src="http://www.google.com" width="100%" height="100%"></iframe>
</span>
If you are using any server side language the page will always look like refreshing itself but if you check the net calls of the page it will shows you one hit for your page and repetitive hits for iframe's src. Hope this will help you out.
Related Topics
How to Show the "Are You Sure You Want to Navigate Away from This Page" When Changes Committed
How to Check Whether a Checkbox Is Checked in Jquery
How to Read CSS Rule Values With JavaScript
Retrieve the Position (X,Y) of an HTML Element
Jquery Mobile: Markup Enhancement of Dynamically Added Content
Difference Between Properties and Attributes in Html
Can One Angularjs Controller Call Another
How to Decode HTML Entities Using Jquery
Invoking JavaScript Code in an Iframe from the Parent Page
Communication Between Tabs or Windows
How to Retrieve an HTML Element'S Actual Width and Height
Why Can't I Call a Function Named Clear from an Onclick Attribute
Selecting All Text in HTML Text Input When Clicked