下载< div>使用JS转换为.doc或.docx [英] Download a <div> to .doc or .docx using JS

查看:164
本文介绍了下载< div>使用JS转换为.doc或.docx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个div的动态内容:

Say I have dynamic content of a div :

//a button to click, or something
<button type="button">Download Content as a .doc</button>

//Div to be downloads as .div
<div class="gc"> //Generated content
   <h1>A Header</h1>
   <p>A Paragraph</p>
   <ul><li>A</li><li>List</li><li>Here</li></ul>
</div>

您可以建议不使用服务器端帮助而采用哪种方法?我对JS持开放态度,因为我目前正在学习此方法,并且可以使用Jquery访问div,只需寻找简单答案或提示正确学习方向即可.

What ways can you suggest approaching this without using server side help? I am open to JS, as I am currently learning this, and can access the div with Jquery, just looking either for a simple answer or a hint down the right direction to learn.

希望它与在div中显示pdf一样简单,例如 ,但我不知道.

Hopefully it is as easy as the oppposite as showing a pdf in a div, like the this, but I don't know.

对于我的特殊情况,内容可以格式化或不格式化,作为对象放置在word或其他一些古怪的解决方法中,或者使用通用的浏览器扩展名.最终,我只希望能够为用户提供内容的.doc(可能是.docx)版本.

For my particular situation, the content can formatted or not, placed as an object within word or some other quirky workaround, or maybe using a common browser extension. Ultimately, I just want to be able to offer the user a .doc (potentially .docx) version of the content.

如果我必须使用服务器端功能,请问有什么好的链接可以帮助我解决问题吗?因为我不了解AJAX或PHP,但愿意学习!

If I MUST use server side functionality, have any good links to help me meander through a solution? as I do not know AJAX or PHP, but am willing to learn!

推荐答案

没有某种服务器端的东西将发送正确的头文件,这是不可能的.

This is not possible without some sort of serverside thing that will send the correct headers.

您可以将.html文件重命名为.doc,单词会吃掉它,但是您仍然需要一些PHP,或者您选择发送任何内容的服务器端语言来发送内容配置下载标签和内容类型application/vnd-ms-word标头.

You can rename a .html file to .doc, and word will eat it, but you will still need some PHP, or whatever serverside language is your drug of choice to send a content-disposition download tag and a content-type application/vnd-ms-word header.

由于明显的安全隐患,这对于纯JavaScript而言是不可能的.

This is impossible with pure javascript, due to obvious security risks.

这篇关于下载&lt; div&gt;使用JS转换为.doc或.docx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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