使用mammoth.browser.min.js在网站上进行docx预览

    <script src="js/mammoth.browser.min.js"></script>
    <script>
        function showDocx(url)
        {
            console.log(url);
            const xhr = new XMLHttpRequest();
            xhr.open("GET", url);
            xhr.responseType = "arraybuffer";
            xhr.onload = function() {
                mammoth.convertToHtml({arrayBuffer: xhr.response})
                .then(function(result)
                {
                    var html = result.value;
                    var message = result.messages;
                    document.write(html); 
                })
                .catch(function(error)
                {
                    console.log(error);
                })
            };
            xhr.send();
        }
    </script>
    <li onclick="showDocx('灵学研究记录.docx')"><a href="#">灵学记录研究</a></li>

 

posted on 2025-12-20 11:05  小沙盒工作室  阅读(0)  评论(0)    收藏  举报