javascript - 在 iframe 中仅显示一个 div(javascript、JQuery...)

标签 javascript jquery iframe html

首先让我说,我对完全不同的方法持开放态度。

我有这样的 iframe:

<div id="testloadlogin">
      <iframe src="../security/login.aspx" width="400" height="500"
             scrolling="auto" frameborder="1">
      [Your user agent does not support frames or is currently configured
      not to display frames. However, you may visit
      <a href="../security/login.aspx">the related document.</a>]
      </iframe>
</div>

用 iframe 加载的页面有一个名为 loginInnerBox 的 div。我只想显示 loginInnerBox 和其中的所有内容。

关于如何做到这一点有什么想法吗?我正在考虑使用某种 Jquery 或 javascript 来删除 iframe 加载的页面上的所有其他内容,但不确定如何访问它......

需要说明的是,我希望页面上 iframe 之外的所有内容都保持不变。我想要等同于说 $.('teSTLoadlogin').load('../security/login.aspx' #loginInnerBox) 这只会获取 loginInnerBox 的 html 并将其放在 teSTLoadlogin div 中。但是,我需要来自 iframe 支持的其他页面的后端处理,而不是 Jquery 加载。

iframe加载的页面标记为

<body>
    <div>
    </div>.......
    <div class="AspNet-Login" id="ctl00_CLPMainContent_Login1">
        <div id="loginInnerBox">
            <div id="loginCreds">
                <table>
                </table>
            </div>
        </div>
    </div>
    <div>
    </div>....
</body>

您还需要更多信息吗?

我试过了,没有效果:

<div class="ui-corner-all" id="RefRes">
        <div id="testloadlogin">
        <iframe onload="javascript:loadlogin()" id="loginiframe" src="../security/login.aspx"
             scrolling="auto" frameborder="1">
      [Your user agent does not support frames or is currently configured
      not to display frames. However, you may visit
      <a href="../security/login.aspx">the related document.</a>]
      </iframe>
        </div>
    </div>
    <script type="text/javascript">
        function loadlogin() {
            $('<body>*', this.contentWindow.document).not('#ctl00_CLPMainContent_Login1').hide();
        }
    </script>

最佳答案

使用 jQuery,您不仅可以加载 URL 的内容,还可以从该 URL 中加载特定的 CSS 选择器。这将是一种更简洁的方法。就像这样。

$("#area").load("something.html #content");

通过CSS Tricks

关于javascript - 在 iframe 中仅显示一个 div(javascript、JQuery...),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4086876/

相关文章:

javascript - Node 需要绝对路径

JavaScript 日期在 HighCharts 上转换为 UTC

javascript - 在javascript中下载数据是否有数据大小限制

c# - HTML 5 list 无法通过 iFrame 正常工作

javascript - IFRAME 中的 jQuery 会影响父窗口的 jQuery 吗?

javascript - HTML 中窗口关闭事件和后退按钮单击事件的区别?

javascript - 在 AngularJS 中更新模块值或重新注册过滤器

javascript - Jquery 选择所有具有数据属性通用名称的元素

ajax - 当试图将一个网站与另一个网站集成时,该怎么做? iframe 还是拉取内容?

javascript - 在 popup.html Chrome 扩展程序中保存用户首选项