0

so the code that extracts the div from the iframe is made by @Adil like this:

$(window).load(function () {
        var filteredContents = $('.test').contents().find('.div_iframe').html();
        $('.test').contents().find('body').html(filteredContents);
});

HTML looks like this:

<iframe class="test" width="100%" height="100%" src="/message.html?msjId=268" style="height:100%;width:100%;">
<iframe class="test" width="100%" height="100%" src="/message.html?msjId=260" style="height:100%;width:100%;">

and the tables that should be displayed now, they should be two different tables, but at the moment is the same table for both msjId but duplicated from the first msjId...

Thanks in advance!

UPDATE:

i will explain more so i don't get close vote what i'm doing is that i have a table in the iframes that i want only to get without any headers or anything so the code above is filtering that to give me exactly that div that contains the table from the iframe and then displays it. my problem is if i have more than one iframe then the table is duplicated from the first iframe with the same info and there's no loop like foreach...

Abude
  • 2,112
  • 7
  • 35
  • 58

1 Answers1

1

When you have more then one elements you can use each to iterate through them, try this.

<iframe id="frame1" width="100%" height="100%" src="/message.html?msjId=268" style="height:100%;width:100%;">
<iframe id="frame2" width="100%" height="100%" src="/message.html?msjId=260" style="height:100%;width:100%;">

 $(window).load(function () {
     $('.test').each(function(){         

       var filteredContents1 = $(this).contents().find('.div_iframe').html();
       $(this).contents().find('body').html(filteredContents1);       

     });

 });
Adil
  • 146,340
  • 25
  • 209
  • 204
  • yes, but it's a dynamic call of the iframe so i can't make ids, my iframe looks like this: ` – Abude Sep 22 '12 at 17:00
  • need help with your code if i do submit action on iframe need to take the next msjId, is it possible ? – Abude Sep 24 '12 at 11:10
  • what i mean is simply if i make an action on the iframe and it reloads then it reloads with all the headers and i want it to reloads like before with only that part, even i don't reload the page and only the iframe reload, do you know what i mean ? – Abude Sep 24 '12 at 11:24
  • After making action you need to execute these statements for every frame that is loaded var filteredContents1 = $(this).contents().find('.div_iframe').html(); $(this).contents().find('body').html(filteredContents1); – Adil Sep 24 '12 at 11:28
  • yes, but how can i do this without reloading the page, i want just the iframe to reload as i wanted without headers :( ? – Abude Sep 24 '12 at 11:30
  • i tried a lot of methods from here but nothing is working :( http://stackoverflow.com/questions/4249809/reload-an-iframe-with-jquery – Abude Sep 24 '12 at 11:43
  • Yes you can do that without loading the frame, what action you perform on that iframe? – Adil Sep 24 '12 at 12:02
  • no, within the iframe html there's a button after that table you know of submit, so if i click submit it submits but reload just the iframe and doesn't apply the script you made anymore because the window is not reloaded :( – Abude Sep 24 '12 at 12:03
  • you can answer there so i can accept you answer for this too, need help :( thanks man ! http://stackoverflow.com/questions/12564684/actions-within-the-iframe-breaks-my-script-jquery – Abude Sep 24 '12 at 12:10