【问题标题】:Target an iframe with only the src attribute provided仅使用提供的 src 属性定位 iframe
【发布时间】:2012-11-08 20:19:27
【问题描述】:

我们有一个页面在底部呈现一些附属脚本。其中一个脚本呈现了一个 iframe,它在某些浏览器中破坏了我们的页面。我们希望阻止显示此 iframe,但它提供给我的唯一属性是 src 属性。我无法使用我的 CSS 广泛定位 iframe,因为其他生成的 iframe 对各种合作伙伴来说都是必需的。

在他们有机会诊断出他们的错误代码之前,我们有没有办法通过它的 src 或使用 CSS 或 JavaScript/jQuery 的东西来定位这个 iframe 并阻止它显示在页面上?

糟糕的 iframe:

<iframe src="https://someurl.net/p.ashx?a=9879&b=3541" height="1" width="1" frameborder="0">

在这个 iframe 里面,文档树去:

<html>
    <head><head>
    <body>
        <pre style="word-wrap:break-word; white-space:pre-wrap;">NF</pre>
    </body>
</html>

【问题讨论】:

标签: javascript jquery html css iframe


【解决方案1】:

这应该可以解决问题:

$('iframe[@src*="someurl.net/p.ashx"]').hide();

【讨论】:

  • @ 符号在属性选择器中的作用是什么?
  • 哎呀。我的错。用 xpath 术语思考,其中@ like 表示查找名为“src”的属性。在 jquery 中是没有必要的。
【解决方案2】:

css 方法是:

iframe[src*="someurl.net"] {
    display: none;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-07
    • 2011-12-05
    • 2018-09-30
    • 2015-02-14
    • 2020-10-17
    相关资源
    最近更新 更多