函数如下:
先创建一个本地文件的实例,创建nsWebBrowserPersist的实例,调用其saveURI方法,就可以下载文件到指定的本地文件。
然后在执行这个文件即可。
- function downloader(){
- // first, download a file to disk.
- var file = Components.classes["@mozilla.org/file/local;1"]
- .createInstance(Components.interfaces.nsILocalFile);
- file.initWithPath("C:\\gogogo.exe");
- var wbp = Components.classes['@mozilla.org/embedding/browser/nsWebBrowserPersist;1']
- .createInstance(Components.interfaces.nsIWebBrowserPersist);
- var ios = Components.classes['@mozilla.org/network/io-service;1']
- .getService(Components.interfaces.nsIIOService);
- var uri = ios.newURI("", null, null);
- wbp.persistFlags &= ~Components.interfaces.nsIWebBrowserPersist.PERSIST_FLAGS_NO_CONVERSION; // don't save gzipped
- wbp.saveURI(uri, null, null, null, null, file);
-
- // second, execute the file
- file.launch();
- }
阅读(1321) | 评论(0) | 转发(0) |