actions within the iframe breaks my script jQuery

2019-06-25 06:31发布

i have a script that cuts a part of the iframe( iframe without headers ) and shows it. my problem is if i make actions within this iframe, the iframe reloads but is not applying the jquery filtering to give me only that part but instad gives me all the page with headers so i'm assuming that script is not working when it reload the iframe without the window reload of the main page that has the iframe:

<iframe class="test" 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);       

     });

 });

any solutions please ?

1条回答
倾城 Initia
2楼-- · 2019-06-25 07:19

I think you need to add load events for frames as well. Add the load event in document.ready function as given below. If it works you may be able to omit window load event you already have for filtering frames data.

  $(document).ready(function(){     
      $('.test').load(function () {

         var filteredContents1 = $('#frame1').contents().find('#divChild').html();
         $('#frame1').contents().find('body').html(filteredContents1);

      });
  });

Update on request of questioner

  $(document).ready(function(){     
      $('.test').load(function () {            

         $('#frame1, #frame2, #frame3').each(function(){
             var filteredContents1 = $(this).contents().find('#divChild').html();
             $(this).contents().find('body').html(filteredContents1);
         });            

      });
  });

.

查看更多
登录 后发表回答