开发者

Developing a Firefox plugin/addon that invokes "Save As" from FF's own set of functions

开发者 https://www.devze.com 2023-03-18 08:54 出处:网络
I have a basic FF addon that polls for something in the DOM of the page in window.document. When it sees it, it is supposed to save the page.That\'s the hard part. I don\'t want to replicate the funct

I have a basic FF addon that polls for something in the DOM of the page in window.document. When it sees it, it is supposed to save the page. That's the hard part. I don't want to replicate the functionality of "save complete" I jus开发者_开发技巧t want to call the pre-existing functionality from the plugin/addon at the right moment.

Is this an XPCom thing? Or is it pure JavaScript via the relevant APIs ?

iMacros for Firefox can invoke Save-as (without popping the associated dialog), but I can't see how.

Can anyone advise as to how to call deeper Firefox functions like this?

Thanks, - Paul

PS - I really love Mozilla Archive Format, with MHT and Faithful Save but I think it is replicating functionality again. My alternative is to invoke it's function, but that's as opaque to me as the firefox native one.


You can use nsIWebBrowserPersist.saveDocument() for this:

var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].
  createInstance(Ci.nsIWebBrowserPersist);
var localPath = Cc["@mozilla.org/file/local;1"].
  createInstance(Ci.nsILocalFile);
localPath.initWithPath(pathToLocalDirectory);
var localFile = localPath.clone();
localFile.append("mylocalfile.html");
persist.saveDocument(document, localFile, localPath, null, 0, 0);

The key is the third parameter which specifies where the linked URIs should be stored. See http://mxr.mozilla.org/mozilla2.0/source/embedding/components/webbrowserpersist/public/nsIWebBrowserPersist.idl#256 for complete documentation.

0

精彩评论

暂无评论...
验证码 换一张
取 消