【问题标题】:How block all iframes with exceptions?如何阻止所有有异常的 iframe?
【发布时间】:2021-08-08 10:54:11
【问题描述】:

我想在所有使用 Greeasy Monkey 的用户脚本的网站上阻止 iframe。我使用这样的脚本:

// @match        *://*/*
window.addEventListener("load", function () {
  var i;
  var iframes = document.getElementsByTagName("iframe");
  var numIframes = iframes.length;
  for (i = 0; i < numIframes; i += 1) {
    iframes[i].style.display = "none";
  }
});

我的问题,如何对某些 URL 进行例外处理?例如hCaptcha.com、ReCaptcha 等

【问题讨论】:

    标签: javascript iframe userscripts


    【解决方案1】:

    一个简单的解决方法是只检查脚本本身中的 URL。

    if (!(window.location.href.indexOf("Captcha") > -1)) {
    //your code  
    }
    

    【讨论】:

    • 仅适用于来自 Google 的 reCaptcha...byt 不适用于 hCaptcha、SloveMedia、2Captcha 等
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-13
    • 2020-07-16
    • 2017-08-14
    • 1970-01-01
    • 1970-01-01
    • 2011-05-01
    • 2021-04-15
    相关资源
    最近更新 更多