0

I'm writing a firefox addon using jquery. I added an iFrame to a page and filled it with another page (allowed due same orign policy).

$('#globalContainer').append('<iframe id="reusable_iframe" src="" width="90%" height="400" name="reusable_iframe"></iframe>');
//....
$('#reusable_iframe').attr('src', link);
//...
var link = $('#reusable_iframe').contents().find(HTMLclass).eq(position).find(searchBy).attr('href');

The problem is, the DOM inside the iFrame isn't finished loading before my access. However, when I add an alert then it works without any problems:

$('#globalContainer').append('<iframe id="reusable_iframe" src="" width="90%" height="400" name="reusable_iframe"></iframe>');
//....
$('#reusable_iframe').attr('src', link);
//...
alert("wait a sec"); //<-------------------------
var link = $('#reusable_iframe').contents().find(HTMLclass).eq(position).find(searchBy).attr('href');

This problem is very similar to my ajax-problem, which also worked with an alert. how to know when the DOM is ready again after adding a node from ajax I haven't found a solution for both problems...

I tried this one: jQuery .ready in a dynamically inserted iframe but it wasn't working for me...

Thank you all =)

Community
  • 1
  • 1
Weedjo
  • 335
  • 1
  • 6
  • 17

1 Answers1

1
$('#globalContainer').append('<iframe id="reusable_iframe" src="" width="90%" height="400" name="reusable_iframe"></iframe>');
//....
$('#reusable_iframe').attr('src', link);

$('#reusable_iframe').load(function(){
    var link = $('#reusable_iframe').contents().find(HTMLclass).eq(position).find(searchBy).attr('href');

});
locrizak
  • 12,192
  • 12
  • 60
  • 80
  • As I already told, this solution isn't working for me. The `.load()` seems never to fire. It's a facebook-page and I guess because all the ajax-requests (for chat) the site is never really finished loading. Any other solutions? – Weedjo Oct 13 '11 at 09:42
  • try rearranging the order of the three things – locrizak Oct 13 '11 at 13:48