js直接打开word文件

1、打开word,会弹出一个对话框,询问打开、保存、取消

window.open("http://localhost/test/test.doc");

2、直接打开word文档

var word = new ActiveXObject("Word.Application");
word.Visible = true;
word.Documents.Open("http://localhost/test/test.doc");

3、不知道与2有什么区别

var openDocObj; 
openDocObj = new ActiveXObject("SharePoint.OpenDocuments.2"); 
openDocObj.editDocument("http://localhost/test/test.doc");




下面是引用过来的,新增一个模板文档

<html>
<head>
<title>打开word文档</title>
<meta http-equir="content-type"

content="text/html";charset="gb2312">
<script language="Javascript">
function doword(doc)                    //doc为你的当前路径下的文件名
{

var url=unescape(window.location.href).replace( "file:///","");
url =url.substring(0,url.lastIndexOf("/")+1).replace("/","//");
url=url+doc;
var WordApp=new ActiveXObject("Word.Application");
WordApp.Application.Visible=true;
var Doc=WordApp.Documents.Add(url,true);
}
</script>
</head>
<body>
<button onClick="doword('test2.doc')">打开Word文档</button>
</body>
</html> 




CKEditor默认情况下不支持直接打开Word文件,但您可以使用第三方插件来实现该功能。 一个很好用的插件是CKEditor Word插件,它允许您在CKEditor中打开和编辑Word文件。您可以在GitHub上找到它的源代码和文档:https://github.com/WebSpellChecker/ckeditor-plugin-word-import 以下是使用CKEditor Word插件的步骤: 1. 下载CKEditor Word插件并将其解压缩到您的网站目录中的“plugins”文件夹中。 2. 在CKEditor配置文件中添加插件的路径和名称: ```javascript config.extraPlugins = 'wordimport'; ``` 3. 在需要打开Word文件的页面上,使用以下代码创建CKEditor实例: ```javascript CKEDITOR.replace('editor1', { filebrowserBrowseUrl: '/path/to/wordimport/browse.php', filebrowserUploadUrl: '/path/to/wordimport/upload.php' }); ``` 请注意,此代码假定您已经将CKEditor Word插件的示例文件夹放置在您的网站根目录下的“path/to/wordimport”中。如果您将插件放置在不同的位置,请相应地更改文件路径。 4. 创建一个名为“browse.php”的文件,该文件打开Word文件选择器,允许用户选择要打开文件。以下是一个示例“browse.php”文件的代码: ```php <?php /** * CKEditor Word Import Plugin Example * * This is a simple example of file browser script that can be used with CKEditor * Word Import Plugin to browse for Word files on your server. */ // Define the path to the Word files folder on your server $word_files_folder = '/path/to/word/files'; // Get the list of Word files in the folder $word_files = glob($word_files_folder . '/*.docx'); // Build the response array $response = array(); foreach ($word_files as $word_file) { $response[] = array( 'name' => basename($word_file), 'url' => $word_file ); } // Send the response as JSON header('Content-Type: application/json'); echo json_encode($response); ``` 请注意,此代码假定您已将Word文件放在您的网站根目录下的“path/to/word/files”文件夹中。如果您将文件放置在不同的位置,请相应地更改文件路径。 5. 创建一个名为“upload.php”的文件,该文件将处理上传的Word文件并返回文件的URL。以下是一个示例“upload.php”文件的代码: ```php <?php /** * CKEditor Word Import Plugin Example * * This is a simple example of file upload script that can be used with CKEditor * Word Import Plugin to upload Word files to your server. */ // Define the path to the Word files folder on your server $word_files_folder = '/path/to/word/files'; // Check if the file was uploaded successfully if (!isset($_FILES['upload']) || $_FILES['upload']['error'] != UPLOAD_ERR_OK) { die('Upload failed'); } // Generate a unique file name $filename = uniqid() . '.docx'; // Move the uploaded file to the Word files folder move_uploaded_file($_FILES['upload']['tmp_name'], $word_files_folder . '/' . $filename); // Return the URL of the uploaded file echo '/path/to/word/files/' . $filename; ``` 请注意,此代码假定您已将Word文件放在您的网站根目录下的“path/to/word/files”文件夹中。如果您将文件放置在不同的位置,请相应地更改文件路径。 以上是使用CKEditor Word插件打开Word文件的一般步骤,您可以按照上述步骤进行操作。但请注意,此插件的使用需要您在服务器端进行一些设置和编程。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值