簡體   English   中英

使用jQuery在iframe中查找元素的高度

[英]Finding height of an element inside iframe using jquery

我剛剛嘗試了一個選擇器,像這樣

$('#message_type_popup').contents().find('#bb-main-content').height();

結果

Error: Permission denied for <file://> to get property HTMLDocument.ownerDocument from <http://www.sample.com>.

我只是在本地嘗試過。 如果我要從同一個域加載iframe,它會起作用。

如果iframe不是來自同一域,則由於瀏覽器具有相同的來源政策 ,因此您將無法使用javascript訪問其內容

這是為了防止跨站點腳本攻擊(XSS)。 iframe的內容應源自同一域,以便您能夠通過JavaScript對其進行操作

關於該主題的一些有趣的閱讀: http : //pipwerks.com/2008/11/30/iframes-and-cross-domain-security-part-2/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM