简体   繁体   中英

altering contents inside iframe and remove unwanted elements

I have a div

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

Now the page loads inside the iframe

I want to remove all the other items except a div inside the iframe

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

But this is not working

Is it possible to do such thing? What should be done?

Remember: The src of iframe should also have to be in the same domain. This is due to security reasons.

Yet you can use load/html such way:

$("#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;
});

using .load() :

$("#container").load($("#survey").contents().find(".requiredDiv"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM