HTML5 / JavaScript:打开文本文件,加载到textarea /将textarea内容保存到文本文件 [英] HTML5 / JavaScript: open text file, load into textarea / save textarea content to text file

查看:268
本文介绍了HTML5 / JavaScript:打开文本文件,加载到textarea /将textarea内容保存到文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在浏览器中做两件事:


  • 将文本文件加载到textarea中(必须通过对话框选择)

  • 将文本区域的内容保存为文本文件(必须再次通过对话框选择)

  • 加载视频文件并抓取文件路径与视频播放器一起使用( 1



我一直在网上寻找一段时间。只有通过ActiveXObjects才有一些解决方案,我不能使用(IE,认真?)。 HTML5文件API的可用性有限,因为我无法访问所选文件的路径。



我还发现保存textareas对话框,但由于某些奇怪的原因它们忽略了换行符,我不知道如何解决这个问题,如果可能的话。



所以这里是我的要求和选项:





  • 支持FF和Chrome

  • JavaScript,HTML5(如果必须的话,可能Silverlight,但我不是很熟悉它,可能只能复制和粘贴: - /

  • 它必须在Mac上工作

  • 文件API是HTML,它允许你访问数据,之后你可以在JavaScript中操作二进制的blob,但是正如所写的那样根据您的要求,在纯JS和HTML中是不可能的。



    大拦截器是保存到文本文件。我能做到这一点的唯一方法是打开一个调用服务器端语言(如PHP)的iFrame,将标题中的内容类型设置为提示下载的类型。



    Flash和Silverlight是在沙盒外运行的客户端技术,这听起来像是您唯一的选择。


    I want to do two things in my browser:

    • Load a text file into a textarea (has to be choosen via dialog box)
    • Save the content of a textarea into a text file (has to be choosen via dialog box again)
    • Load a video file and grab the file path to use it with a video player (1)

    I've been looking around for a while on the internet. There are some solutions for IE only via ActiveXObjects, which I can't use (IE, seriously?). HTML5 file API has limited usability because I can't access the selected file's path.

    I also found save dialogs for textareas, but they ignored line breaks for some strange reason and I don't know how to fix that, if possible at all.

    So here are my requirements and options:

    • Support for FF and Chrome
    • JavaScript, HTML5 (and PHP, if it has to be)
    • possibly Silverlight, but I'm not very familiar with it and may only copy and paste :-/
    • it has to work on Mac as well

    解决方案

    The File API is HTML that would allow you to access data, after which you can manipulate binary blobs in JavaScript, but as written this is not possible in pure JS and HTML based on your requirements.

    The big blocker is "saving to a text file." The only way I've been able to do this is by opening up an iFrame that calls a server side language (such as PHP) to set the content type in the header to a type that prompts a download.

    Flash and Silverlight are "client" technologies that run outside of the sandbox, which sounds like your only option at this point.

    这篇关于HTML5 / JavaScript:打开文本文件,加载到textarea /将textarea内容保存到文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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