Actions inside iframe break my jQuery script

I have a script that cuts a part of an iframe (an iframe without headers) and shows this. my problem is that I am doing actions inside this iframe, the iframe reloads but does not apply jquery filtering to give me only this part, but instad gives me the whole page with the headers, so I assume the script does not work when reloading the iframe without reloading the main page window with 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?

+4
source share
1 answer

I think you need to add load events for frames. Add a load event to the document.ready function, as shown below. If it works, you can omit the window load event that you already have for filtering frame data.

  $(document).ready(function(){ $('.test').load(function () { var filteredContents1 = $('#frame1').contents().find('#divChild').html(); $('#frame1').contents().find('body').html(filteredContents1); }); }); 

Poll request update

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

.

+1
source

Source: https://habr.com/ru/post/1435905/


All Articles