如何在Greasemonkey或Tampermonkey中排除iframe? [英] How to exclude iframe in Greasemonkey or Tampermonkey?

查看:449
本文介绍了如何在Greasemonkey或Tampermonkey中排除iframe?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为网站创建了一个Greasemonkey脚本。该脚本的作用是在页面末尾添加一个div。

I have created a Greasemonkey script for a website. What the script does is adding a div at the end of the page.

document.body.insertBefore(myDiv, document.body.firstChild);

但现在该网站为google-ads添加了一个iframe,结果我的div出现在iframe中这也不是我想要的。

But now the site adds an iframe for google-ads, as a result my div appears in the iframe too, which is not what I want.

如何停止影响iframe的脚本?

How can I stop the script affecting iframes?

推荐答案

Greasemonkey现在支持 @noframes 指令 (Tampermonkey和Scriptish长期支持)。

使用它来更简洁地阻止iframe中的操作。

Greasemonkey now supports the @noframes directive (long supported by Tampermonkey and Scriptish).
Use that for a cleaner way to block operation in iframes.

不幸的是,现在 npdoty的回答在Firefox的浏览器控制台中触发警告:

Unfortunately, npdoty's answer will now trigger a warning in Firefox's browser console:


警告:不推荐使用函数外部的返回,并且可能导致Greasemonkey的未来版本出现故障。

Warning: use of return outside of functions is deprecated and may cause failures in future versions of Greasemonkey.

这篇关于如何在Greasemonkey或Tampermonkey中排除iframe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆