Can We read client side files using javascript

T

Thomas 'PointedEars' Lahn

Thomas said:
Yes, with XHR, but only from a file: URI to a file: URI, or with a
privileged script. In MSIE 7+ you are required to use the ActiveXObject
object instead of XMLHttpRequest for that.

Just in case anyone is interested, the following works from a `http:' URI in
Fx 2.0.0.13 if the supporting feature is enabled[1]:

try
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
netscape.security.PrivilegeManager.enablePrivilege("UniversalFileRead");
var x = new XMLHttpRequest();
x.open("GET", "file:///C:/AUTOEXEC.BAT", true);
x.onreadystatechange = function() {
if (x.readyState == 4) window.alert(x.responseText);
};
x.send(null);
}
catch (e)
{
e
}

It is important that both privileges are requested and granted. Firebug
then still displays

| Security Error: Content at http://... may not load or link to
| file:///C:/AUTOEXEC.BAT.

but the content of the file is displayed anyway. Code running out of the
sandbox does not have to request the privileges though, so be careful with
what extensions you install :)


PointedEars
___________
[1]
http://developer.mozilla.org/en/docs/Bypassing_Security_Restrictions_and_Signing_Code
 
T

The Magpie

Thomas said:
Yes, with XHR, but only from a file: URI to a file: URI, or with a
privileged script. In MSIE 7+ you are required to use the ActiveXObject
object instead of XMLHttpRequest for that.
You can with XMLHttpRequest, Pointed. It doesn't really care what type
the files are as long as they are text-content (not binary).
 
T

Thomas 'PointedEars' Lahn

The said:
You can with XMLHttpRequest, Pointed. It doesn't really care what type
the files are as long as they are text-content (not binary).

It would appear you are replying to something I have not written.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top