简体   繁体   中英

Print a word document in javascript instead of downloading it

I have a link which points to a .docx or PDF file. 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()')

Resource interpreted as Document but transferred with MIME type application/zip.

You can not tell the browser to print a specific document, since window.print will only bring up the print dialog. ( MDN )

JavaScript is not very useful for handling files, but you can use Flash. I googled it and I found a link which it maybe works for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM