Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery and frames - $(document).ready doesn't work

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 frame, $(document).ready() doesn't fire up.

My frameset looks like:

<frameset rows="79,*" frameBorder="1" frameSpacing="1" bordercolor="#5996BF" noresize> 
    <frame name="header" src="Operations.aspx?main='Info.aspx'" marginwidth="0" marginheight="0" scrolling="no" noresize frameborder="0">
    <frame name="main" src="Info.aspx" marginwidth="0" marginheight="0" scrolling="auto" noresize frameborder="0">      
</frameset>

My page is loaded into the main frame. What should I do?

like image 361
matma Avatar asked Oct 21 '08 08:10

matma


People also ask

Why is my document ready not working?

The "$(document). ready is not a function" error occurs for multiple reasons: Placing second set of parenthesis after the call to the ready() method. Loading the jQuery library after running your JavaScript code.

Is $( document .ready necessary?

No, it is not necessary. You can either put the script tag right before the body closing tag or if you are supporting IE9+ you can use native JS.

How can I implement my own $( document .ready functionality without using jQuery?

Your answer There are three options: If script is the last tag of the body, the DOM would be ready before script tag executes. When the DOM is ready, "readyState" will change to "complete" Put everything under 'DOMContentLoaded' event listener.

What does $( document .ready function () do?

$( document ).ready()A page can't be manipulated safely until the document is "ready." jQuery detects this state of readiness for you. Code included inside $( document ).ready() will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute.


2 Answers

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.

like image 165
jenming Avatar answered Oct 10 '22 09:10

jenming


I know this is an old topic. But to help some of you who reach this page, here is my solution:

$($("#frameName")[0].contentWindow.document).ready(function() {
    // Write you frame onready code here
});
like image 27
elfan Avatar answered Oct 10 '22 08:10

elfan