Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  10] [ 7]  / answers: 1 / hits: 30035  / 12 Years ago, wed, july 11, 2012, 12:00:00

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?


More From » jquery

 Answers
5

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

[#84334] Tuesday, July 10, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
susanajamiep

Total Points: 466
Total Questions: 113
Total Answers: 108

Location: Liberia
Member since Fri, Oct 22, 2021
3 Years ago
susanajamiep questions
Sun, Jun 12, 22, 00:00, 2 Years ago
Mon, Mar 7, 22, 00:00, 2 Years ago
Wed, Jun 10, 20, 00:00, 4 Years ago
Fri, Jan 24, 20, 00:00, 4 Years ago
;