Photo sets in Tumblr are served up as iFrames.
I want to manipulate that iframe via jQuery to look the way i want it too, which I'm able to do, but it doesn't always finish what it's doing.
I think it's because there is a lot of things happening concurrently as the page loads. I need a way to check that this iFrame, which I have no control over, loads 100% before i do the fun stuff.
There are various techniques suggested in other questions about this, but I don't think they are right for this situation. Here's one example from the Stack Overflow question "jQuery .ready in a dynamically inserted iframe"
function callIframe(url, callback) {
$(document.body).append('<IFRAME id="myId" ...>');
$('iframe#myId').attr('src', url);
$('iframe#myId').load(function()
{
callback(this);
});
}
But that makes no sense to me whatsoever to me, even though it got ticked and had 100 upvotes. In this 'answer' the iframe is being appended by the function. That to me is not a dynamically loaded iframe!
Here is my code with the 'dumb' iframe load checker. The code works, but only sometimes. You can see it in action here http://syndex.me (third post is a photoset)
$(".post_relative").each(function () {
var post_relative = $(this);
var photoset = post_relative.find('.html_photoset');
if(photoset.length){
var myFrame = photoset.find("iframe");
myFrame.load(function(){
var newCover=myFrame.contents().find('.photoset').children(':first-child').children(':first-child').attr("href")+ '?'+(Math.random()*10000);
post_relative.append("<img src='"+ newCover +"' alt='Cover Page' />");
var psHeight = post_relative.find('img');
psHeight.load(function(){
if (psHeight.height()>heightRef){
psHeight.height(heightRef);
}
myFrame.hide();
})
})
}
});
So the question is: How do you execute a script based on the 100% loading and readiness of an iframe?