Prevent Execution in Frames
From GreaseSpot
Sometimes if the page you are seeing on screen contains frames with addresses that your script is set to run on (via @include and @exclude rules). You may not always want this to happen - for example alert() messages may appear multiple times or other odd behaviour.
Do not run on frames or iframes
To stop this happening, you can check to see if the page your script is currently running as the 'top' page as follows:
if (window.top !== window.self) {
return;
}
Selectively run on frames vs top-level documents
Alternatively you may wish to run different code depending upon whether the Greasemonkey script is being run inside a frame or as the top document, as opposed to simply exiting the script in one case or the other.
if (window.top === window.self) {
// Not in a frame
/** Do something specific to iframes **/
} else {
// In a frame
/** Do something specific to frames **/
}