【发布时间】:2011-07-21 17:05:54
【问题描述】:
我想使用 JavaScript 动态创建一个文档,然后在 Microsoft Word 中打开该文档。这可能吗?这是我当前的代码:
<html>
<head>
<title></title>
<script src="js/jquery-1.4.4.js" type="text/javascript"></script>
</head>
<body>
<div id="myDiv">The quick brown fox jumped lazly over the dead log.</div>
<script type="text/jscript">
var printWindow = window.open("", "Print", "width=800,height=400,scrollbar=0");
var printAreaHtml = $("#myDiv").attr("outerHTML");
printWindow.document.open("text/html", "replace");
printWindow.document.writeln("<html><head>")
printWindow.document.writeln("<meta HTTP-EQUIV='Content-Type' content='application/vnd.ms-word'>");
printWindow.document.writeln("<meta HTTP-EQUIV='Content-Disposition' content='attachment;filename=print.doc'>");
printWindow.document.writeln("</head>");
printWindow.document.writeln("<body>");
printWindow.document.write(printAreaHtml);
printWindow.document.writeln("</body>");
printWindow.document.writeln("</html>");
printWindow.document.close();
// printWindow.print();
</script>
</body>
</html>
【问题讨论】:
-
你想达到什么目的?
-
理论上您可以创建正确的二进制数据并以可以正确保存的方式显示它,但是这通常是在服务器端完成的,以便可以执行正确的 mime 类型和数据转换。
标签: javascript jquery