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


<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Titletitle>
    <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>

第二种方法


<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Titletitle>
    <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>

你可能感兴趣的:(javascript)