Thomas 'PointedEars' Lahn wrote:
parveen wrote:
>Can We read client side files using javascript? not only text files
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...d_Signing_Code
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16