Need method for loading text files




17 years ago
5 years ago


(Reporter: Jeff Yates, Assigned: Heikki Toivonen (remove -bugzilla when emailing directly))



Firefox Tracking Flags

(Not tracked)




17 years ago
I was hoping that the Mozilla team could add a method to enable JavaScript to 
load a text file without using a frame.  Using a frame causes the history to 
change (thus effecting forward/back buttons).

IE implements this using behaviors.  This would be a sample of how they 
implement it:

<body style="behavior: url( #default#download );">
<script type="text/javascript">
function callback( sText ){
  //  deal with the text here
document.body.startDownload( url, callback );

I know that Mozilla is not implementing behaviors (XBL but not behaviors), but 
I do not think that XBL offers a mechanism to download a file and return it's 
contents as text/plain format.

By the way, IE's method works for text/HTML and text/XML so I assume it works 
for any text/* mime-type.

I feel this will add tremendous scripting power (say as an external data 
source) and would like to see this implemented.

Jeff Yates
Heikki, this can be done with the XMLHttpRequest thingy, right?
Assignee: jst → heikki
Right. XMLHttpRequest is the object you want. Despite its name, it can send and
retrieve plain text as well.

In your case you would use it something like this:

var r = new XMLHttpRequest();

function myfunc() {

r.onload = myfunc;"GET", "");

For more information see the XML Extras page on

There is a link to Microsoft documentation of XMLHttpRequest (it was invented by
Microsoft, we try to mimic it closely). There should also be links to a couple
of samples.

Jeff, does this work for you?

Comment 3

17 years ago
Two questions, but it seams to be good to me so far.

1) Is XMLHttpRequest included by default with Mozilla 0.8.1?  I noticed that it 
is on nightlies from the week before 0.8.1.

2) Can XMLHttpRequest use the "file://" protocol if the web page is being 
served from the users computer?  This can be worked around but I prefer not to 
during developement.

I was going to mark this as work-for-me, but someone here might want to make 
this a part of a default binding.  I will leave that up to ya'll.

Jeff Yates

Comment 4

17 years ago
Tested this method using 0.8.1 (build 2001032319) and it worked just fine.  The 
only problem that I see is that the XMLHttpRequest does NOT allow relative 
URL's nor the "file://" protocol.  

I am going to check to see if there is a bug report on the relative URL's and 
if not then I will put one in.

I do not think that this object is designed for the "file://" protocol so some 
other method will be needed for this.

Yes, it is in the default builds and installers starting with 0.8.1.

file protocol should work, there should be no difference to any other protocol
(might be bugs, though, file 'em if you find 'em).

Relative URLs should also work, if they don't think might be a regression since
I think they worked for me earlier.

Marking this as worksforme.
Last Resolved: 17 years ago
Resolution: --- → WORKSFORME


15 years ago
QA Contact: lchiang → ian
v per comments
Component: DOM: Mozilla Extensions → DOM
Product: Core → Core
You need to log in before you can comment on or make changes to this bug.