diff --git a/chrome/content/zotero/xpcom/file.js b/chrome/content/zotero/xpcom/file.js index 6728f8627..67e8af888 100644 --- a/chrome/content/zotero/xpcom/file.js +++ b/chrome/content/zotero/xpcom/file.js @@ -25,6 +25,7 @@ Zotero.File = new function(){ this.getClosestDirectory = getClosestDirectory; this.getSample = getSample; this.getContents = getContents; + this.getContentsFromURL = getContentsFromURL; this.putContents = putContents; this.getCharsetFromFile = getCharsetFromFile; this.addCharsetListener = addCharsetListener; @@ -115,6 +116,20 @@ Zotero.File = new function(){ } + /* + * Return the contents of a URL as a string + * + * Runs asynchronously, so should only be run on local (e.g. chrome) URLs + */ + function getContentsFromURL(url) { + var xmlhttp = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"] + .createInstance(); + xmlhttp.open('GET', url, false); + xmlhttp.send(null); + return xmlhttp.responseText; + } + + /* * Write string to a file, overwriting existing file if necessary *