From edb66a779c7683f37bc36b10a61b08c575e49eb9 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 20 Jul 2007 18:19:03 +0000 Subject: [PATCH] Zotero.File.getContentsFromURL(url) --- chrome/content/zotero/xpcom/file.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 *