iframe中的动作打破了我的脚本jQuery [英] actions within the iframe breaks my script jQuery

查看:109
本文介绍了iframe中的动作打破了我的脚本jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本可以切割iframe的一部分(iframe无标题)并显示它。我的问题是,如果我在此iframe中执行操作,iframe将重新加载,但不会应用jquery筛选以仅给出该部分,但instad会向我提供所有带有标题的页面,所以我假设该脚本在重新加载iframe没有窗口重新加载具有iframe的主页面:

 < iframe class =testwidth =100 %height =100%src =/ message.html?msjId = 260style =height:100%; width:100%;> 
$ b $(window).load(function(){
$('。test')。each(function(){

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

});

});

有什么解决方法吗?

解决方案

我想你也需要为框架添加加载事件。在document.ready函数中添加load事件,如下所示。如果它有效,您可能可以省略过滤帧数据的窗口加载事件。

(函数(){
$('。test')。load(函数(){

var filteredContents1 = $('#frame1')。contents()。find(' (); $ b $('#frame1')。contents()。find('body')。html(filteredContents1);

});
});

更新询问者的请求



<$ p $ (函数(){
$('。test')。load(function(){
$ b $('#frame1 ,#frame2,#frame3')。each(function(){
var filteredContents1 = $(this).contents()。find('#divChild')。html();
$(this ).contents()。find('body')。html(filteredContents1);
});

});
});


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 ?

解决方案

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);
         });            

      });
  });

.

这篇关于iframe中的动作打破了我的脚本jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆