Hmm, that should work - pretty sure we've used that to load local files 
in the past. Note that window.alert() won't work in commands - use 
displayMessage() or CmdUtils.log() instead. So if that's what you've 
tested with, then that's probably the problem.

Failing that, have a look at:
https://developer.mozilla.org/en/Code_snippets/File_I%2f%2fO#Reading_from_a_file

Its not as simple, but it should at least work.

Also, what version of Ubiquity are you running? 0.1.2 or the development 
version?

- Blair





On 30/11/2008 3:25 AM, Aurimas wrote:
> Thanks for your answer. It works. But not for local files. This
> command doesn't work:
>
> function cmd_load(){
>    jQuery.get('file:///C:/Disk/Web/ubiq/commands.js', function(data) {
>      window.alert(data);
>    });
> }
>
> Is it possible to load a local file?
>
>
> On Nov 29, 1:25 pm, Blair McBride<[EMAIL PROTECTED]>  wrote:
>> Sorry for jumping in so late on this...
>>
>> CmdUtils.injectJavascript() will inject JavaScript into the *current tab
>> content*. Which means it will run with content privileges - not what you
>> want if you want it for your command. Then accessing that code opens the
>> possibility of other code from that page intercepting it, and gaining
>> chrome privledges - which would be very bad.
>>
>> The correct way of doing this is to load it via a XMLHttpRequest (ie,
>> Ajax). Using jQuery, the code would be:
>>
>> jQuery.get("http://example.com/script.js";, function(data) {
>>     eval(data);
>>     doStuff();
>>
>> });
>>
>> Just be very careful about what code you're fetching. Make sure you can
>> definitely trust it, as it will be running with full chrome privileges,
>> so can do everything a command can do. Ubiquity doesn't yet have an easy
>> way to ensure a safe sandbox, although it should by the time v0.2 comes out.
>>
>> If its just JSON data, use Utils.decodeJson() instead - its always safe
>> to use that, even with untrusted data.
>>
>> Also, note that if any commands depend on the functionality in remote
>> code, they won't work until that code is loaded. So you may wish to put
>> all your commands (ie, calls to CmdUtils.CreateCommand()) inside the
>> callback (ie, where the call to doStuff() is). You could also load it
>> inside of every preview/execute method of the commands that use depend
>> on that code (I think the browser should cache the remote script
>> automatically).
>>
>> - Blair
>>
>> On 28/11/2008 4:39 AM, [EMAIL PROTECTED] wrote:
>>
>>> Hi,
>>> I am not sure if this was covered before, but I have a external .JS lib
>>> that I want to be able to call within my ubiquity command. Can anyone
>>> give me any pointers? From some previous thread, I think
>>> CmdUtils.injectJavascript needs to be used. Is this correct?
>>> thanks,
>>> --
>>> Mayuresh
>>
> >

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"ubiquity-firefox" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/ubiquity-firefox?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to