admin管理员组文章数量:1221300
I have an iframe loaded dynamically with jQuery like this
jQuery('<iframe id="myFrame" src="iframesrc.php"></iframe>').load(function(){
// do stuff when loaded
}).prependTo("#myDiv");
And I want to catch the reload event every time the inner frame is reloaded. I tried this:
jQuery('body').on('load', '#myDiv', function() {
alert('iframe loaded');
});
But I'm not getting any response, both on the initial load and when following links inside the iframe. What am I doing wrong?
I have an iframe loaded dynamically with jQuery like this
jQuery('<iframe id="myFrame" src="iframesrc.php"></iframe>').load(function(){
// do stuff when loaded
}).prependTo("#myDiv");
And I want to catch the reload event every time the inner frame is reloaded. I tried this:
jQuery('body').on('load', '#myDiv', function() {
alert('iframe loaded');
});
But I'm not getting any response, both on the initial load and when following links inside the iframe. What am I doing wrong?
Share Improve this question asked Jul 11, 2012 at 12:15 LobsterManLobsterMan 1,2081 gold badge13 silver badges20 bronze badges2 Answers
Reset to default 18You 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
for new url
location.assign("http:google.com");
The assign() method loads a new document.
reload
location.reload();
The reload() method is used to reload the current document.
本文标签: javascriptCatch iframe reload with jQueryStack Overflow
版权声明:本文标题:javascript - Catch iframe reload with jQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739360681a2159803.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论