A simple question (as indicated in the title): Is jQuery.ready() valid when used on iframe.contentDocument ?
And the tricky question:
I need to connect the keyup event in the input field in the CMS, so I can not control the HTML, only the script.
The input is inside an iframe, which is nested in another iframe, so there is a top window (browser window), iframe (allows you to call it iframe1) and another iframe inside it (allows you to call one iframe2). script and jQuery are in the <head> section of the top window.
I don't really like setTimeout/setInterval , so my initial thought was to use jQuery.ready() like this (I skipped the code that selects iframes):
$(document).ready(function(){ $(iframe1.contentDocument).ready(function(){ $(iframe2.contentDocument).ready(function(){ $("input").keyup(function(){ }); }); }); });
The problem is that by the time .ready() iframe1 is triggered, I can check iframe1.contentDocument.body.innerHTML and this will be an empty string. Not what one would expect. As a result of this code, it is not possible to bind a keyup event.
In case someone thinks: βAre you using the correct selector context?β: Yes, I select iframe elements in the correct documents (although the above code snippet may not fully explain this, since I just wanted to save it). There is also no problem with the origin policy - all iframes and parent windows are in the same domain.
Using $(window).load() seems to work, but waiting for images to load, etc. Waiting time is too long, which is not acceptable for the application.
Is it possible to achieve jQuery.ready() functionality that will work with an iframe without using jQuery.load() ?
javascript jquery iframe document-ready
Woodgnome May 03 '11 at 13:21 2011-05-03 13:21
source share