开发者

Get data from inside an iFrame on the same page

I am trying to do something like this:

 var data = $('#upTar').contents();
 $("#fileRes").html(data);

Where 开发者_开发百科#upTar is an iframe and #fileRes is a div, that is I want all the data from iframe (in HTML format) into the div. The iframe is dynamically loaded.

Edit

The additional code looks like:

    $("#addMore").click(function() {  
         $("#progForm").submit();  
         $('#upTar').load(function() {  
         $("#title, #obj, #theory, #code, #output, #conc").val("");  
         var data = $('#upTar').contents().find("body").html();  
         alert(data);    
         $("#fileRes").html(data);  
        });  
     });  

The target for form submit is an iframe (#upTar) on the same page. Once that one is loaded, I want its data to be transfered to div.

CLOSURE EDIT

Rather than trying to fetch the details from the iframe, I now call an ajax script to update the div.

Thanks All!


try $('#upTar').contents().find("body").html()

contents itself return top-level HTMLElement node, you have to grab HTML from this node too. and you possibly don't want all the HTML including the head section, so first you need to find body tag.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜