[英]Print a word document in javascript instead of downloading it
I have a link which points to a .docx or PDF file. 我有一个指向.docx或PDF文件的链接。 When a user clicks on the link, instead of downloading/showing it...I would like to popup a print window.
当用户单击链接时,而不是下载/显示它...我想弹出一个打印窗口。 I tried doing the following but I'm getting an error:
我尝试执行以下操作,但出现错误:
var e = document.getElementById("download_1");
e.print();
return false;
Embed file: 嵌入文件:
<embed src ="/files/test.doc" width="0" height="0" name="download_1"></embed>
I'm getting an error: 我收到一个错误:
TypeError: 'undefined' is not a function (evaluating 'e.print()') TypeError:“未定义”不是函数(计算“ e.print()”)
Resource interpreted as Document but transferred with MIME type application/zip. 资源被解释为文档,但以MIME类型application / zip传输。
You can not tell the browser to print a specific document, since window.print
will only bring up the print dialog. 您不能告诉浏览器打印特定文档,因为
window.print
仅会弹出打印对话框。 ( MDN ) ( MDN )
JavaScript is not very useful for handling files, but you can use Flash. JavaScript对于处理文件不是很有用,但是您可以使用Flash。 I googled it and I found a link which it maybe works for you.
我搜索了它,发现了一个可能对您有用的链接 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.