使用webOffice插件,页面自动打开Word文档

1.官网下载js,并把js放到页面要显示的元素里面

在这里插入图片描述

2.在body上添加onload方法

在这里插入图片描述

3.js里面编写代码

在这里插入图片描述
代码如下:

function WebOpen(){
	obj = document.getElementById('WebOffice');//获得控件对象
	if (obj)setTimeout('openfile()',1000);//等待控件初始化完毕,时间可以根据网络速度设定。
}
function openfile()
{
	 //获取文件名
	var pfile="hi.docx";
	var strOpenUrl=""; 
	$.ajax({
		type : "post",
		url : "../../br/detial/problem/getTomcatPath",
		data :"",
		dateType : "json",
		success : function(result) {
			strOpenUrl= result+"detialProblemImg/"+ pfile ; //取得打开路径和文件名 
			document.getElementById('WebOffice').Open(strOpenUrl,false,"Word.Document");
			/* document.getElementById('WebOffice').LoadOriginalFile("http://localhost:8080/MTJC/detialProblemImg/hi.doc","doc"); */
		}
	});
} 

特别提醒:运行插件需要安装插件环境,官网都有下载

发布了9 篇原创文章 · 获赞 4 · 访问量 3145

猜你喜欢

转载自blog.csdn.net/weixin_43642706/article/details/89405067