如何强制iframe刷新

问题描述:

用iframe做菜单时,二级菜单的src只是后边的参数不同,这时如果只是采用

$('#content iframe').attr('src',href);
这时可以看到iframe的src改变了,但是页面没有跳转,
原因:iframe此时认为你的src没有改变
刷新方法:
document.getElementById(iframe的ID).contentWindow.location.reload(true);
不能采用self.location.reload();方法,采用此方法,刷新整个界面,导致iframe回到初始状态
代码贴上:
//点击菜单跳转
var $div = $('.main-sidebar > .sidebar-menu');
$div.on('click', 'li[data-href]', function () {
   var href = $(this).data('href');
   if (!!href && href!='undefined') {
      var curSelf = $('#content iframe').attr('src');
      var curPos = curSelf.lastIndexOf('#');
      var curPar = curSelf.substr(curPos);
      var pos = href.lastIndexOf('#');
      var par = href.substr(pos);
      $('#content iframe').attr('src',href);
      if(par != curPar && curPos !=-1){
         document.getElementById('iframe').contentWindow.location.reload(true);
      }
      //菜单增加样式
      if($(this).parents('li').data('href') == undefined){
         $(this).addClass('active');
         $(this).parent('ul').siblings().find('li').removeClass('active');
      }else{
         $(this).parents('li').addClass('active');
         $(this).parents('li').parent('ul').siblings().find('li').removeClass('active');
      }
   }
   return false;
});


  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

愤怒的小青春

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值