Trying to figure this out... I'm trying to accessthe top level of the dom from inside an iframe. How possible is this?
+1
A:
To use selectors and jQuery functions in the inner DOM of an iframe, you can use the Traversing/contents function.
$("iframe").contents().find("body").append("I'm in an iframe!");
CMS
2009-06-30 19:03:47
I know that, but how do I access the outside world from inside the iframe?
Reactor5
2009-06-30 19:11:46
+2
A:
You can append window.parent.document to your calls to get to the parent.
e.g.
$('body', window.parent.document).append("this is coming from my iframe");
Edit: As noted in the comments below the iframe must be served from the same domain as the parent or the browser's security restrictions will prevent this.
Gareth Simpson
2009-06-30 19:19:35
+1
A:
From inside of a frame you can always get to the top level using window.top
. You can check to see if you are in a frame using:
var iAmInAFrame = (window.top == window.self);
You should be able to use window.top.document.whatever
(e.g. body, getElementById(), etc.) to manipulate the top level document provided that you share a domain.
Prestaul
2009-06-30 20:39:38