[Jslib] jslib include() for remote script

Pete Collins pete at mozdev.org
Thu Sep 18 21:28:03 EDT 2003


> Thanks.  I have the following code working:
> ------------------------------------------
> include (jslib_remotefile);
> 
> function includeRemote(sSomeHTTPURL){
>       try{
>              var rf = new RemoteFile(sSomeHTTPURL);
>              var jsfile;
>              rf.open();
>              jsfile = rf.read();
>              eval(jsfile);
>       }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!


Cool. Good to know it works. I need to get something like this into jslib.

What I think i'll do is add a hook the the include method that will test 
the URL for the http protocol.

So then we can just do this:

include ("http://www.path/to/my/jsFile.js");

That would be real nice!

--pete

-- 
Pete Collins
www.mozdev.org
www.mozdevgroup.com




More information about the Jslib mailing list