I'm trying to prevent my Greasemonkey script from executing within IFRAMEs. I'm doing so by using if (window.top != win开发者_StackOverflow中文版dow.self) return;
. As soon as I insert that line right after the metadata header, the error console throws out a "Security Manager vetoed action" indicating this exact line of code. There's no additional information available.
I'm using Firefox 3.6.10 and the latest Greasemonkey extension. Oh, I'm new to user scripts but even after some time looking for an answer I didn't find anything at all.
Greasemonkey has an own API, which allows persistent storage and cross-site HTTP requests. For this reason, scripts are executed in a sandbox and this API cannot abused.
To make your code work, use:
if(usnafeWindow.top != unsafeWindow.self) return;
Please note the unsafe
part, you may want to review these pages:
- http://wiki.greasespot.net/Security
- http://wiki.greasespot.net/Avoid_Common_Pitfalls_in_Greasemonkey
Alternatively, wrap the code in a <script>
tag:
(function(f){var d=document,s=d.createElement('script');s.setAttribute('type','application/javascript');s.textContent = '('+f.toString()+')()';(d.body||d.head||d.documentElement).appendChild(s);s.parentNode.removeChild(s)})(function(){
/* code here */
}
精彩评论