簡體   English   中英

如何在Greasemonkey或Tampermonkey中排除iframe?

[英]How to exclude iframe in Greasemonkey or Tampermonkey?

我已經為網站創建了Greasemonkey腳本。 該腳本的作用是在頁面末尾添加一個div。

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

但是現在該網站為Google-ads添加了一個iframe,結果我的div也出現在了iframe中,這不是我想要的。

如何停止影響iframe的腳本?

我將其放在腳本的頂部,以避免在框架或iframe上運行:

if (window.top != window.self)  //don't run on frames or iframes
    return;

Greasemonkey現在支持@noframes指令 (Tampermonkey和Scriptish長期支持)。
使用它可以更簡潔地阻止iframe中的操作。


不幸的是, npdoty的答案現在將在Firefox的瀏覽器控制台中觸發警告:

警告:不建議在函數外部使用return,這可能會導致Greasemonkey未來版本的失敗。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM