elfio wrote:
> (snip)
>> No, you will not.  Like I said above, user scripts are separate.  (You
>> _could_ access them, with unsafeWindow: but like the name says, it is
>> unsafe!  You should not use it.)
>>     
>
> But I need access to some variables of the page. How can I do it
> without use unsafeWindow?
>   
Probably the easiest way to do this is by injecting part of the script 
into the page. That way, the script you inject runs as though it was 
included in the page, and has full access to all the page's variables, 
functions, etc, but has no direct access to various privileged 
Greasemonkey APIs. To do this, append a <script> element to the page 
with contents set to whatever you're injecting; it's easiest to inject 
whole functions, because you can simply do something like the following:

function example(param1, param2) {
  // Do something with its parameters
  return param1.toString() + param2.toString();
}
var elemScript = document.body.appendChild(document.createElement("script"));
elemScript.innerHTML = example + "\n\n window.alert(example(1,2));  // Call 
example from in-page code";

and the function's source will be included in that <script> element 
without much work.

By the way, when Anthony says something is unsafe, he unfortunately 
means it. unsafeWindow can be *very* unsafe, because it allows the most 
seemingly innocent of script operations to be perverted by a malicious 
web page and do all kinds of nasty things with e.g. Firefox internals -- 
for example, making unrestricted cross-domain requests (to your bank, 
perhaps?); performing denial-of-service attacks with GM_setValue; and 
all kinds of other things.
Don't use it.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"greasemonkey-users" group.
To post to this group, send email to greasemonkey-users@googlegroups.com
To unsubscribe from this group, send email to 
greasemonkey-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/greasemonkey-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to