Cannot modify content of iframe, what is wrong?

前端 未结 3 1199
迷失自我
迷失自我 2020-11-29 09:52

I am trying to modify content of an iframe but it does not work.

This is my main.html


Main page
&         


        
3条回答
  •  执念已碎
    2020-11-29 10:04

    Please don't forget the cross-domain policy, otherwise it won't work.

    Live demo: http://jsfiddle.net/oscarj24/wTWjF/

    (Just to know, I am not using a 404 page, take a look)

    Try this:

    $(document).ready(function(){
        $('#ifr').ready(function(){
            $(this).contents().find('body').html('Hey, I have changed the body content yay!');
        });
    });​
    

提交回复
热议问题