将编辑器 html 保存到客户计算机

发布于 2024-11-16 00:44:49 字数 617 浏览 0 评论 0原文

我的页面上有一个CKEditor,以便允许用户在线编辑html。

我想添加到页面的功能之一是能够使用“保存模板”之类的按钮保存编辑器的内容,随后将出现保存/打开窗口,而不会出现安全警告或页面刷新。

我意识到 Javascript 无法访问客户端的文件系统,因此我无法使用它来创建和保存文件。

我的下一个方法是将编辑器内容发送到服务器,将其保存为文件,然后将其发送回用户。

因为我不想刷新页面,所以我使用了 AJAX 方法来保存设计。

现在在 OnSucceed javascript 函数中,我激活了一个隐藏的 iframe,它从服务器检索文件,但这会激活 IE 安全警告...

我尝试同时触发方法和 iframe,现在没有警告,但是iframe 总是在 AJAX 方法之前执行...

还有其他方法可以做到这一点吗?我错过了一些简单的事情吗...?

编辑:

中的建议使用 iframe 和 UploadPanel

我按照http://encosia.com/ajax- 文件下载和 iframes/

I have a CKEditor at my page, in order to allow users to edit html online.

one of the features I want to add to the page is the ability to save the contents of the editor with a button like "Save Template", which will be followed by the save/open window, without security warnings or page refresh.

I realize that Javascript can't access the client's file system, so I can't use it to create and save a file.

my next approach was to send the editor contents to the server, save it as a file and then send it back to the user.

since I don't want the page to refresh I used an AJAX method to save the design.

now at the OnSucceed javascript function I activated an hidden iframe which retrieves the file from server, but this activates an IE security warning...

I've tried to fire both method and iframe at the same time now there are no warnings, but the iframe gets executed always before the AJAX method...

is there any other way to do this? am I missing something simple...?

EDIT:

I used iframe with UploadPanel as suggested in

http://encosia.com/ajax-file-downloads-and-iframes/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

油饼 2024-11-23 00:44:49

我会走类似的路线 - 将其发送到服务器的往返过程中。事实上,这就是我实现从服务器检索文件的各种页面的过程 - 但我从未在我编写的内容中遇到过安全警告(但我不使用 asp.net)。

您没有说明安全警告是什么 - 也没有说明 SSL 是否以任何方式涉及。

我建议您构建一个测试装置,用户只需按下按钮即可触发 JavaScript 并编译服务器上静态数据的响应 - 由您的代码介导。请注意,如果您希望下载文件,那么您应该在响应标头中这么说,例如

Content-Disposition: attachment; filename="yourfile.html"

您也可以尝试返回浏览器未明确支持的 mimetype 来强制下载:

Content-type: application/octet-stream

HTH

I would have gone down a similar route - sending it on a round trip to the server. Indeed, that's the process by which I've implemented all sorts of pages for retrieving files from a server - but I've never come across a security warning from stuff I've written (but I don't use asp.net).

You didn't say what the security warning is - nor if SSL is involved in any way.

I suggest you build a test rig where the user just presses a button to trigger the javascript and compile the response from static data on the server - mediated by your code. Note that if you want the file to donwload then you should say so in the response headers e.g.

Content-Disposition: attachment; filename="yourfile.html"

You might also try returning a mimetype not explicitly supported by the browser to force download:

Content-type: application/octet-stream

HTH

染墨丶若流云 2024-11-23 00:44:49

我建议您使用客户端 SessionStorage 或 LocalStorage 以便以后访问。使用图书馆来缓解您的生活KIZZY 来了

I Would recommend you use Clients SessionStorage or LocalStorage for later access. use the library to ease your life Here comes KIZZY

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文