Saturday, 24 August 2013

How do you detect when a frame has loaded

How do you detect when a frame has loaded

I have a project where I dynamically load pages into a frame. The pages
are within the same domain, but I do not have access to the page content.
I cant figure out how to detect when the pages load. See simplified
version below using on and ready which didnt work.
Note, I have come across similar questions but they are either to do with
iframes or not dynamically loaded.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd"><html
xmlns="http://www.w3.org/1999/xhtml" >
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type = "text/javascript" >
$(document).ready(function(){
$(window.mainContent.document).ready(function() {
console.log("loaded1");
});
$(window.mainContent.document).on("load", function() {
console.log("loaded2");
alert("loaded");
});
setTimeout(function(){
window.mainContent.location.href = "page1.html";
}, 1000);
});
</script>
</head>
</head>
<frameset rows="100%">
<frame name="mainContent" id="mainContent" />
</frameset>
</html>

No comments:

Post a Comment