是否可以使用javascript读取文件? [英] is it possible to read a file using javascript?

查看:74
本文介绍了是否可以使用javascript读取文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我只想知道是否可以使用

Hi all i just want to know if we can read a file using javascript like

我们做什么

fp=("r","path")

像那样有可能吗?

推荐答案

首先,我认为使用JavaScript在本地读取文件不是一个好主意.我建议先将其上传到服务器,然后再执行阅读.

Firstly I think its not a good idea to read a file locally with JavaScript. I recommend first upload it to the server and then perform the reading.

尽管有可能,但是您受自己的能力的限制.

Having said that it is possible, but you restricted by what you can do.

我假设它是用户计算机上的本地文件,否则AJAX将在服务器读取时实现此目的.

Im assuming its a local file on the user machine, otherwise AJAX would achieve this for a server read.

有可能通过

  1. Windows脚本宿主对象模型(WScript.Shell)和 授予提示或启用访问权限时 升级到ActiveX浏览器 特权(通过工具"> Internet选项>安全性>自定义 级别...>将Active X设置设置为 迅速的).如果仍然很难,用户可以下载已安装的内容,然后通过Shell脚本进行读取! 免责声明:注意,我不推荐这种方法.它由于某种原因不活跃,而且很脏(我感觉很脏)!

  1. Windows Script Host Object Model(WScript.Shell) and when granted Prompt or Enable access to ActiveX the browser has elevated privileges (Enable through Tools > Internet Options > Security > Custom Level ... > Set Active X settings to prompt). If this is still to difficult, user could download something thats installed and then does the reading through Shell Scripting! Disclaimer: Note I do not recommend this approach. Its not active for a reason and its so DIRTY (I feel dirty)!

Cookie可能也值得考虑.如果您可以将信息存储在cookie中,则JavaScript可以读取,写入和更新它.

Cookies might also be worth considering. If you can store the information in a cookie the JavaScript would be able to read, write and update it.

http://www.quirksmode.org/js/cookies.html 向右滚动到底部 例子.

Found this code from http://www.quirksmode.org/js/cookies.html scroll right to the bottom for the example.

function createCookie(name,value,days) {
if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";

}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name,"",-1);
}

这篇关于是否可以使用javascript读取文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆