2009-06-30 73 views

回答

5

從框架內部,您始終可以使用window.top來達到最高級別。你可以檢查一下,如果你是在一個框架使用:

var iAmInAFrame = (window.top == window.self); 

您應該能夠使用window.top.document.whatever(如身體,的getElementById()等)來操縱頂層文件,前提是您共享域。

1

要在iframe的內部DOM中使用選擇器和jQuery函數,可以使用Traversing/contents函數。

$("iframe").contents().find("body").append("I'm in an iframe!"); 
+0

我知道,但是如何從iframe中訪問外部世界? – 2009-06-30 19:11:46

4

您可以將window.parent.document添加到您的調用中以獲得父級。

例如

$('body', window.parent.document).append("this is coming from my iframe"); 

編輯:由於在iframe下面的評論指出,必須從同一個域中父母或瀏覽器的安全限制會阻止這種送達。

+2

+1。只要iframe可以訪問父級(相同的域)。 – 2009-06-30 19:22:33