[英]how to create a doc file using Javascript and HTML
我有一个网页我想要当用户点击按钮然后它必须创建一个doc文件,其中包含以下信息,如Name等和Designation我们在php和.net中创建一个文件库,所以在html中有这样的方式所以我们可以在项目的根文件夹中创建文件。
You cannot create them on server as HTML and JS both are for client-side only. 您无法在服务器上创建它们,因为HTML和JS都仅用于客户端。 Even then, if you wish to do something like this client-side in future, use the following info :
即便如此,如果您希望将来做这样的客户端,请使用以下信息:
Two methods are defined in the specifications, 1) createDocument from DOM Core Level 2 and 2) createHTMLDocument from HTML5. 规范中定义了两种方法,1)来自DOM Core Level 2的createDocument和来自HTML5的createHTMLDocument 。
The former creates an XML document (including XHTML), the latter creates a HTML document. 前者创建XML文档(包括XHTML), 后者创建HTML文档。 Both reside, as functions, on the DOMImplementation interface.
两者都作为函数驻留在DOMImplementation接口上。
var impl = document.implementation,
xmlDoc = impl.createDocument(namespaceURI, qualifiedNameStr, documentType),
htmlDoc = impl.createHTMLDocument(title);
Actually, these methods are rather young and only implemented in recent browser releases. 实际上,这些方法相当年轻,仅在最近的浏览器版本中实现。 According to http://quirksmode.org and MDN, the following browsers support createHTMLDocument :
根据http://quirksmode.org和MDN,以下浏览器支持createHTMLDocument :
Chrome 4 Chrome 4
Opera 10 歌剧10
Firefox 4 Firefox 4
Internet Explorer 9 Internet Explorer 9
Safari 4 Safari 4
You can create a HTML document in older versions of Internet Explorer, using ActiveXObject : 您可以使用ActiveXObject在旧版Internet Explorer中创建HTML文档:
var htmlDoc = new ActiveXObject("htmlfile");
The resulting object will be a new document, which can be manipulated just like any other document. 生成的对象将是一个新文档,可以像处理任何其他文档一样进行操作。
HTML and JavaScript run on the client, but to create a file in the root folder of the project requires a procedure on the server. HTML和JavaScript在客户端上运行,但要在项目的根文件夹中创建文件,需要在服务器上执行一个过程。 Luckily, there is a common standard technology for this form of communication: AJAX.
幸运的是,这种通信形式有一种通用的标准技术:AJAX。 Your process might run like this:
您的进程可能会像这样运行:
If you use JQuery, or any other standard JavaScript framework, they'll have an AJAX library already built in. 如果您使用JQuery或任何其他标准JavaScript框架,他们将内置一个AJAX库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.