[Jslib] jslib include() for remote script

Ryan Maw rmaw at forge-industrial.com
Thu Sep 18 18:15:58 EDT 2003

Pete Collins wrote:

> Ryan Maw wrote:
>> I would like to use the include() method in jslib to load a script 
>> file from a remote http server, for example:
>> include("http://www.somedomain.net/myscript.js");
>> I would like this script to be included into the script in my chrome 
>> window so the functions that are in the script have full access to 
>> other objects/functions in the chrome window, etc.  I have tried this 
>> but am having problems.  Is this possible?
>> If not, any ideas on how I might incorporate remote script into a 
>> chrome window without using the <script src=..."/> tag?  I want the 
>> user of the chrome app to be able to load in a script file after the 
>> app has started.  I have tried setting the src="" attribute on a 
>> script tag but this doesn't seem to work when the <script> tag is 
>> part of a chrome window (it does seem to work when the tag is part of 
>> an html doc that is loaded into a mozilla browser.)  Help!
> Yea, I know how to implement this. But won't have time for a while.
> But i think you can do something like this.
> include (jslib_remotefile);
> var rf = new RemoteFile("http://www.somedomain.net/myscript.js");
> var jsfile;
> if (rf.exists()) {
>   rf.open();
>   jsfile = rf.read();
>   rf.close();
> }
> eval(jsfile); 

Thanks.  I have the following code working:
include (jslib_remotefile);

function includeRemote(sSomeHTTPURL){
              var rf = new RemoteFile(sSomeHTTPURL);
              var jsfile;
              jsfile = rf.read();
       }catch(e){ alert("unable include remote file:\n" + sSomeHTTPURL + 
"\n Error: " + e); }

The trick is not having any functions in your remote js file because 
they will eval inside the includeRemote function.  To get around this I 
create a general object first and add on methods (someRemoteFile.js):
      oMyObject.prototype.someMethodName  = function () {
          ... method code here

Works great!
Many thanks!

More information about the Jslib mailing list