js打开word文档,而不是下载

时间:2021-07-19 19:01:25
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script> function openmydoc(path) { var doc = new ActiveXObject("Word.Application"); doc.visible = true; doc.Documents.Open(path); } </script>
</head>
<body>

<a onclick="openmydoc('D:\\word\\go.doc');" type="activxobject(word.application)">
    点击我!!!打开word文档,而不是下载
</a>
</body>
</html>

第二种方法

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script language="Javascript"> function doword() { var WordApp = new ActiveXObject("Word.Application"); WordApp.Application.Visible = true; var Doc = WordApp.Documents.Add("D:\\word\\go.doc",true); //下面是以只读方式打开 var openDocObj = new ActiveXObject("SharePoint.OpenDocuments.1"); openDocObj.EditDocument("http://localhost/cmt/go.doc"); } </script>
</head>
<body>
<button onclick="doword()">打开Word模板</button>
</body>
</html>