$(document).ready(function(){ $...">

How to add element to parent body from iframe?

I have this code in an iframe.

<script type="text/javascript">
    $(document).ready(function(){
        $("body").append($("#ctap").html());
    });
</script>

I want to add #ctap html to the parent body. How can i do this?

+5
source share
3 answers

Try to execute part of the code inside document.ready

parent.$("body").append($("#ctap").html());
+6
source

If the parent body , you should have something like this:

var iFrame = $('#iframe_id');
var iContent = iFrame.contents().find("#ctap").html();
$("body").append( iContent );
0
source

To be able to access the contents of the main page from an iframe, they must have exactly the same location (host name and port) due to restrictions on the use of scripts in different domains.

See How to remove an iframe from the parent page using a function inside the iframe?

0
source

All Articles