2017-03-01 11 views
0

私はdivの今のiframe内の内容を変更したり削除不要な要素

は、私は、IFRAME内のdiv要素を除く他のすべての項目を削除したいのiframe内のページのロード

<div id="container"> 
<iframe id="survey" src="somepage"></iframe> 
</div> 

に持って

$("#container").html($("#survey .requiredDiv").html()) 

しかし、これに動作していない

それは、そのようなことを行うことは可能ですか?何をすべきか?

+1

あなたは '内容を(使用してみました)'の代わりに? 'var frame = $( '#survey')。contents();' –

+1

あなたはこれを読んでいますか? http://stackoverflow.com/a/15556150/7599559 –

答えて

1

覚えておいてください:srciframeも同じドメインにする必要があります。これはセキュリティ上の理由によるものです。

しかし、あなたはロード/ htmlのような方法を使用することができます:​​を使用して

$("#container").html(function(){ 
    // There could be multiple target elements, i guess you should loop and return the html 
    var htm = ''; 
    $("#survey").contents().find(".requiredDiv").each(function(){ 
     htm += this; 
    }); 
    return htm; 
}); 

を:

$("#container").load($("#survey").contents().find(".requiredDiv")); 
関連する問題