I have a page, with some code in js and jQuery and it works very well. But unfortunately, all my site is very very old, and uses frames. So when I loaded my page inside a fr
I have tried the method mentioned in another comment:
$("#frameName").ready(function() {
// Write you frame on load javascript code here
} );
and it did not work for me.
this did:
$("#frameName").load( function() {
//code goes here
} );
Even though the event does not fire as quickly - it waits until images and css have loaded also.
This answer may be late, but this reply may help someone like me...
This can be done via native Javascript code -
ifrm2 = var ifrm2 = document.getElementById('frm2');
if (ifrm2.contentDocument.readyState == 'complete') {
//here goes the code after frame fully loaded
}
//id = frm2 is the id of iframe in my page
I assume this is a similar problem I was having with DOMContentLoaded in an iframe.
I wrote a blog post about it.
If you want to fire the onload
event for your frames, then follow these steps:
Assign an id
and name
to each <frame>
tag. Make sure both id
and name
attributes value is same.
Use the following code to fire the onload
event of the frame:
$("frameName").ready(function() {
// Write your frame onload code here
}
No need to modify the markup. Just fix the selector. It should be:
$("frame[name='main']").ready(function(){..});
not
$("#frameName").ready(function(){..});
Note: it seems the jQuery ready event fires multiple times. Make sure that is OK with your logic.
There is no reason for $(document).ready()
not to be called.
Be sure your page contains an include to jquery.js
. Try to do a simple test with an empty HTML page and just an alert to see if there is another problem.
If you are trying to use this inside the HTML page that contains the frame's definition, keep in mind that there is no document there, you will have to use the