views:

20

answers:

1

Given an html page with:

<iframe frameborder="0" allowtransparency="true" tabindex="0" src="" title="Rich text editor, editor_kama, press ALT 0 for help." style="width: 100%; height: 100%;"><html><body><p>replace me</p></body></html></iframe>

How can I access the iframe assuming I can't give the iFrame a name or ID since it's made dynamically and also assuming that there is always only 1 iFrame on the page?

I'd like to be able to replace everything in the body tag within the iframe with "found me" or something like that.

Ideas? Thxs

A: 

Try a tag selector

$("iframe")

See Element Selector

rahul
I tried: $(document).ready(function(){alert( $("iframe body").text());}); but that results with null
AnApprentice
Due to cross-domain scripting security issues, you can only alter contents of an iframe if it generates from your same domain (so if your site is www.mysite.com, the iframe needs to be loading content from mysite.com). Also, in your example there, you're trying to alter the text on document.ready, but you said your iframe was created dynamically (after page load?), so just be sure that you're not trying to change the text until after the iframe loads.
RussellUresti
It's on the same domain... How do I make sure i wait for the iFrame?
AnApprentice
Use `$("iframe").load()`
rahul
What would that do? $("iframe").load()
AnApprentice