By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,504 Members | 1,190 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,504 IT Pros & Developers. It's quick & easy.

Can We read client side files using javascript

P: n/a
Can We read client side files using javascript? not only text files
Jun 27 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Jun 27 '08 #2

P: n/a
parveen <k.*******@gmail.comwrites:
Can We read client side files using javascript? not only text files
Yes. No. Some. Depending on what you mean.

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Jun 27 '08 #3

P: n/a
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
Jun 27 '08 #4

P: n/a
The Magpie wrote:
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.
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
Jun 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.