jquery/javascript: accessing contents of an iframe

Posted by rz on Stack Overflow See other posts from Stack Overflow or by rz
Published on 2008-12-13T07:20:34Z Indexed on 2010/04/02 18:33 UTC
Read the original article Hit count: 227

Filed under:
|
|

I would like to manipulate the html inside an iframe using jquery.

I thought I'd be able to do this by setting the context of the jQuery function to be the document of the iframe, something like:

$(function(){//document ready
    $('some selector', frames['nameOfMyIframe'].document).doStuff()
});

However this doesn't seem to work. A bit of inspection shows me that the variables in frames['nameOfMyIframe'] are undefined unless I wait a while for the iframe to load. However, when the iframe loads the variables are unaccessible (I get permission denied type errors).

Does anyone know of way to work around this?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about iframe