Use webOffice plug-in, the page automatically opens the Word document

1. official website to download js, js and put into the elements of the page to be displayed inside

Here Insert Picture Description

2. Add method on body onload

Here Insert Picture Description

Write code inside 3.js

Here Insert Picture Description
code show as below:

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"); */
		}
	});
} 

Special note: run plugins need to install plug-in environment, the official website has downloads

Released nine original articles · won praise 4 · Views 3145

Guess you like

Origin blog.csdn.net/weixin_43642706/article/details/89405067