Well, it's certainly possible to get Greasemonkey to run against an iframe -- in fact, it's a common question to determine how to stop it from executing on iframes as well as the main page. You should be able to take the converse of that answer to prevent code from executing on the top window:
if (window.top == window.self) //don't run on the top window
return;
//rest of the actual executing code goes here
I've tested it and you can use @include
to match domain B (the domain of the iframe
) and run a piece of arbitrary code that modifies it. I ran the following test userscript on a test page and it successfully hides the Google logo (only when Google is in an iframe
).
// @include http://www.google.com*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// ==/UserScript==
if (window.top == window.self) //don't run on top window
return;
alert('running on a frame');
$('img').each(function() {
$(this).hide();
});
So far as I can tell, there aren't any cross-domain restrictions involved here. I'm not sure what happens if the iframe
isn't present when the page is first loaded (which is when Greasemonkey runs).