Posts

Showing posts with the label Userscripts

Apply A Greasemonkey/Tampermonkey/userscript To An Iframe?

Answer : In Greasemonkey (And Tampermonkey and most userscript engines) a script will fire on an iframe automatically if it meets the @include, @exclude, and/or @match directives. And, a popular question is how to stop Greasemonkey from firing on iframes. So, if your script had a match like: @match https://fiddle.jshell.net/* It would fire on jsFiddle "output" pages whether or not they appeared in an iframe. If you wanted to fire on a JUST iframed content: Then you would check the window.self property. For example, suppose you had a target page like: <body> <h1>I'm some webpage, either same-domain or not.</h1> <iframe src="//domain_B.com/somePath/somePage.htm"> ... Then you could use a script like: // ==UserScript== // @name _Fires specially on domain_B.com iframes // @match *://domain_B.com/somePath/* // ==/UserScript== if (window.top === window.self) { //--- Script is on domain_B.com when/if it is the M...