【问题标题】:div is not found in iframe在 iframe 中找不到 div
【发布时间】:2015-09-11 11:31:20
【问题描述】:

在产品升级到最新版本后,我必须解决一个问题。 html 已更改,因此 iframe 内应隐藏的对象现在可见。

我没有进行自定义以在 iframe 中显示产品,我不太了解它是如何工作的,但有人告诉我应该查看这个文件 iframeloader.aspx,特别是名为 function hideTitle() 的函数

我只能访问 iframe 的主应用程序。我可以编辑 iframeloader.aspx。我更新了原始的 hideTitle 函数,使其看起来

  function hideTitle() {         

      var ele = $('#contentFrame');
      ele.load(function() {
console.log("test")
      var menubar = $('#header');
          if (menubar) {
console.log("test2")    
console.log(document.getElementById("header").style.display);
console.log(menubar.html())
              menubar.css("display", "none");
          }
      });
  }

在控制台我可以看到这个

test - iframel...strator (line 700)
test2 - iframel...strator (line 704)
TypeError: document.getElementById(...) is null

在萤火虫中我可以看到 html <div id="header">

当页面加载时,我可以看到我想要隐藏的对象出现,然后是来自 console.log() 的消息

任何想法

  • 如何隐藏#header 对象和
  • 为什么 jQuery 和 javascript 找不到对象?

【问题讨论】:

    标签: javascript jquery css iframe


    【解决方案1】:

    用这个隐藏它:$('#header').hide()

    iframe 里面的东西很难够到,因为它变成了一个新窗口,用这个修改它:

    $('some selector', frames['nameOfMyIframe'].document).doStuff();
    

    【讨论】:

    • $('#header', frames['#contentFrame'].document).hide(); 给我 TypeError: frames['#contentFrame'] is undefined 。 html 看起来像<iframe class="scaleFrame" id="contentFrame"。我做对了吗?
    • 给 iframe 起一个名字 - name="thisIframe",然后使用 $('#header', frames['thisIframe'].document).hide();
    • 我无法给它命名。
    • 无论如何都要给它一个名字 $('#contentFrame').attr('name','thisIframe');
    • 试试 $("#contentFrame").contents().find(whatever)
    猜你喜欢
    • 2021-10-13
    • 2021-09-27
    • 1970-01-01
    • 2019-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-28
    • 1970-01-01
    相关资源
    最近更新 更多