frameReady works a lot like $(document).ready() with a few advantages
when working with frames:

$.frameReady(function,target,remote,jQuery);

-- Waits for the DOM to be ready in the target frame before running
code.
-- It can be run from within any frame or the root document.
-- Function is a standard anonymous function written as though you're
working with local elements.
-- Target can be any valid frame reference, including nested frames
and iFrames.  Must be a string.
-- Remote (default true) runs the function in the context of the
target frame so you can do $("p") instead of $
("p",top.iFrame.mainFrame.document).
-- jQuery (default true if remote is true) will load jQuery in the
target frame before trying to run code if it doesn't exist there
already.  (you will need to specify a valid path for jQuery.js inside
the plugin).

Example:

$.frameReady(function(){
   $("body").prepend('<div id="newDiv">I'm a div</div>');
   $("#newDiv").css("color","red");
},"top.mainFrame");

It has only been tested in FF2 and IE7, so caveat emptor.  If there is
any interest in this I'll spend some time optimizing it.  At the
moment I'm using it on an intranet so it does what I need.

Demo & source here: http://ideamill.synaptrixgroup.com/?p=6

Reply via email to