简体   繁体   English

有没有办法从特定文件中的 contenteditable 数据框中保存和检索文本? (所有客户端)

[英]Is there a way to save and retrieve text from contenteditable data box in a specific file ? (All client side)

I'm making statistical reports for customers and I chose HTML solution as report template.我正在为客户制作统计报告,我选择了 HTML 解决方案作为报告模板。

I have this issue where I want a user to be able to edit a text box of a html document and save it (as soon as he leave the area or when clicking save button) to annotate things like graphics for instance.我有这个问题,我希望用户能够编辑html 文档的文本框并保存它(只要他离开该区域或单击保存按钮时)以注释诸如图形之类的东西。

The content should be printed each time he opens back the .html file.每次他打开 .html 文件时,都应该打印内容。 Also, there are potentially multiple html pages inside the report (one editable box per sub html pages is enough)此外,报告内可能有多个 html 页面(每个子html页面一个可编辑框就足够了)

Moreover, a big constraint here is that this html file is open locally and should be shared across users (I have to stick with this all-client side solution for now but I'm planning on doing it server side).此外,这里的一个很大限制是这个html文件在本地打开并且应该在用户之间共享(我现在必须坚持这个全客户端解决方案,但我打算在服务器端做它)。

As you may have understood already I can't use localStorage solution as it is system/user dependant and data won't stick if people are sharing the report.正如您可能已经了解的那样,我不能使用localStorage解决方案,因为它依赖于系统/用户,并且如果人们共享报告,数据将不会保留。

I'd rather go with a solution where it is possible to save it in a $UID .txt file for instance (one $UID for each sub pages people wants to annotate) and retrieve it so as long as the state of the editable content is saved at the same place in the report folder architecture, it will be opened as is by every other people when they get this edited report.我宁愿选择一种解决方案,例如,可以将其保存在$UID .txt 文件中(人们想要注释的每个子页面一个$UID )并检索它,只要可编辑内容的状态保存在报告文件夹架构中的同一位置,当其他人收到此编辑的报告时,它将按原样打开。

Thanks for your time !谢谢你的时间 !

A.一个。

EDIT编辑

I should have stipulated few things :我应该规定几件事:

1- The report is composed of hundred of stand-alone html files. 1- 报告由数百个独立的 html 文件组成。 It is basic html and javascript components that are translated by a classic web browser without the need of an internet connexion or a localhost server.它是由经典网络浏览器翻译的基本 html 和 javascript 组件,无需 Internet 连接或 localhost 服务器。

2- Folder structure : 2- 文件夹结构:

root_folder
  |
  |---- index.html (main page to access all sub pages)
  |---- graphics
          |---- graphic1.html
          |---- graphic2.html

3- People need to share the report on their own and there is no user database. 3-人们需要自己共享报告,并且没有用户数据库。 The only constraint is that after performing a modification on an editable content box, the text should be written somewhere in the folder structure (see 2) and retrieved automatically the next time some user (either the original editor or the next one on an other computer as long as the first editor shared the whole directory with its own edit) will open (or refresh) the html file.唯一的限制是,在对可编辑的内容框进行修改后,文本应写入文件夹结构中的某处(参见 2),并在下次某个用户(原始编辑器或另一台计算机上的下一个编辑器)时自动检索只要第一个编辑器与自己的编辑共享整个目录)将打开(或刷新)html文件。

I know that there are better solutions but I really have to stick with a stand-alone solution for now, hoping that there is a solution to this issue !我知道有更好的解决方案,但我现在真的必须坚持使用独立的解决方案,希望有解决这个问题的方法!

Thanks again for your time.感谢你的宝贵时间。

If there is no server-side component and you don't want to use the browser's (sandboxed) local storage (be that LocalStorage, IndexedDb or otherwise) then you are left with FileReader to read data and creating Blob URLs to download data.如果没有服务器端组件并且您不想使用浏览器的(沙盒)本地存储(无论是 LocalStorage、IndexedDb 还是其他),那么您将使用FileReader来读取数据并创建Blob URL 来下载数据。

The user experience would be something like this:用户体验将是这样的:

  1. The user opens your (local) .html file用户打开您的(本地).html 文件
  2. They are prompted to open the database (could be text file(s)) with a <input type="file"> .系统会提示他们使用<input type="file">打开数据库(可能是文本文件)。
  3. You use the FileReader api to load this file.您使用FileReader api加载此文件。 Note: you can't use fetch or XMLHttpRequest to do this automatically.注意:您不能使用fetchXMLHttpRequest自动执行此操作。
  4. When the user has finished entered their content, store it in a Blob object and then create a data: -link with createObjectURL .当用户完成输入内容后,将其存储在Blob 对象中,然后创建一个data: -link with createObjectURL You could put that generated url in a <a href="..." download>Save</a> link.您可以将生成的 url 放在<a href="..." download>Save</a>链接中。

As it would be up to your users to make sure they select the proper database file(s) and to save them under the right file name, this is not ideal.由于您的用户需要确保他们选择正确的数据库文件并将它们保存在正确的文件名下,所以这并不理想。 I would strongly recommend a (self-)hosted solution.我强烈推荐一个(自)托管的解决方案。 That could deal with multiple concurrent users a whole lot better, too.这也可以更好地处理多个并发用户。

A server-side component doesn't have to be complex: If you start in a language you're comfortable with and use a SQLite database, you'll go very far in a less complex set-up than what you're describing.服务器端组件不必很复杂:如果您从一种您熟悉的语言开始并使用 SQLite 数据库,那么您将在比您所描述的更简单的设置中走得更远。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 javascript从客户端保存/加载图像+文本数据 - javascript save/load image + text data from client side 在客户端验证动态文本框中的数据 - validate data on dynamic text box at client side 如何在客户端具有用于另存为的对话框以从服务器保存xml文件 - How to have a dialog box for save as to save a xml file from server, on client side 在客户端从Javascript(或任何其他方式)创建文本文件? - Creation of a text file from Javascript (or any other way) on the client side? 从 contenteditable 填充和保存文本 - Populate and save text from contenteditable 如何在客户端保存JSON文件并在以后检索? - How to save a JSON file on the client side and retrieve it later? 如何将抓取的数据从客户端浏览器保存到用户文件? 使用电子? - How to save scraped data from client-side browser to a user file? Use Electron? 使用Django-tables2时,是否可以从客户端动态地从HTML生成的表中获取所有数据? - When using Django-tables2, Is there a way to get all the data from the HTML generated table dynamically and client side? 在Cordova / PhoneGap的客户端文件中打开/保存客户端数据 - Open/save client-side data in a client-side file in Cordova/PhoneGap 从extjs中的表单字段验证并获取JSON文件(所有客户端,无服务器)中的数据。 绝对的菜鸟 - Validating and getting data in a JSON file (All client side, no server) from form fields in extjs. Absolute beginner
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM