最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

cross domain - How can JavaScript get data from a user's computer? - Stack Overflow

programmeradmin0浏览0评论

How can Javascript (running from a website on a remote server) access data from a user's local puter? I have access to all the user's puters and they are all using Chrome. The data may be stored in a file, a database, I can even run a webserver on their puters if needed, etc. Is there any way for my users to for example allow my website to access data from JavaScript? (maybe be there is a Chrome setting but I still want their browser to be secure)

How can Javascript (running from a website on a remote server) access data from a user's local puter? I have access to all the user's puters and they are all using Chrome. The data may be stored in a file, a database, I can even run a webserver on their puters if needed, etc. Is there any way for my users to for example allow my website to access data from JavaScript? (maybe be there is a Chrome setting but I still want their browser to be secure)

Share Improve this question asked Nov 10, 2011 at 21:53 MatthewMatthew 11.3k11 gold badges55 silver badges70 bronze badges 2
  • You can distribute a Chrome plugin, or use a Java applet. – Rob W Commented Nov 10, 2011 at 21:55
  • 2 Why do you want a browser for that? Since you say you can run a server on their puter, I think that might be a better choice since it has a lot more permissions. If it's because you want JavaScript, try Node.js. – pimvdb Commented Nov 10, 2011 at 21:56
Add a ment  | 

4 Answers 4

Reset to default 5

As far as I know, you cannot access the files on the user's machine using javascript. This would be a huge security hole. You have to write a client (not web) application (windows app or whatever technology you are using).

this is not possible just using a browser, because as you said yourself it would`t be secure. You can use some kind of plugin which your users have to allow which then can access the local data on the puter.

It sounds like you are flexible as to where the data is stored in the user's puter. In that case use localStorage or Web SQL Databases. Web SQL Databases are no longer part of the HTML5 spec, but they are supported by Chrome. Using either of these methods will store the data on the users puter - right in the browser in fact.

Edit: In the application that provides the caller id data, have it launch your website with chrome passing in a querystring argument containing the needed caller id data. Then in your page, have it listen to the onstorage event, and update the dropdown when the appropriate localStorage data has changed.

In your caller id app, call:

%ChromeInstallPath%\chrome.exe "http://foo./caller?Bill+Gates@425-882-8080"

In your caller handler, use this JavaScript:

window.onload = function() {
    localStorage.callerId = location.search;
};

In your page with the drop down list, use this JavaScript:

window.onstorage = function() {
    setDropDownFromCallerId(localStorage.callerId);
};

What do you mean by access? does the server-side code need to grab additional info during processing a request?

Is this data that is exclusive to your app (that is, only you create, read, update it.)

If this data is exclusive to your app, then why not store it in HTML 5 Local Storage

发布评论

评论列表(0)

  1. 暂无评论