1、请安装下面链接地址的插件包
目前版本:官网 点击打开链接
2、安装插件包完成后调整加载weboffice的容器
- <object id="Control"
- TYPE="application/x-itst-activex"
- ALIGN="baseline" BORDER="0"
- WIDTH="95%"HEIGHT="600px"
- clsid="{E77E049B-23FC-4DB8-B756-60529A35FAD5}"
- event_NotifyCtrlReady="NotifyCtrlReady"
- event_NotifyToolBarClick="NotifyToolBarClick"
- event_NotifyWordEvent="NotifyWordEvent">
- </object>
<object id="Control" TYPE="application/x-itst-activex" ALIGN="baseline" BORDER="0" WIDTH="95%"HEIGHT="600px" clsid="{E77E049B-23FC-4DB8-B756-60529A35FAD5}" event_NotifyCtrlReady="NotifyCtrlReady" event_NotifyToolBarClick="NotifyToolBarClick" event_NotifyWordEvent="NotifyWordEvent"> </object>
其中的三个事件如下所示:
- //初始化控件 可以初始化加载文档等和设置weboffice的相关属性
- function NotifyCtrlReady() {
- document.all.Control.LoadOriginalFile("E:\\WordDemo\\Demo\\Demo\\doc\\model.doc", "doc");
- }
- //监听工具栏的事件
- function NotifyToolBarClick(id) {
- //eventinfo.innerText = "NotifyToolBarClick 事件发生,工具栏ID:" + id;
- }
- //监听word操作事件
- function NotifyWordEvent(name) {
- //eventinfo.innerText = "NotifyWordEvent 事件发生,Word事件名称:" + name;
- }
//初始化控件 可以初始化加载文档等和设置weboffice的相关属性 function NotifyCtrlReady() { document.all.Control.LoadOriginalFile("E:\\WordDemo\\Demo\\Demo\\doc\\model.doc", "doc"); } //监听工具栏的事件 function NotifyToolBarClick(id) { //eventinfo.innerText = "NotifyToolBarClick 事件发生,工具栏ID:" + id; } //监听word操作事件 function NotifyWordEvent(name) { //eventinfo.innerText = "NotifyWordEvent 事件发生,Word事件名称:" + name; }
3、如何让编辑页面根据浏览器不同装载不同的object对象?
这个可以考虑使用IF IE的浏览器条件注释来达到装载不同object对象的目的。具体的核心装载代码如下所示:
- <!--[if IE]>
- <object id="WebOffice1" height="600px" width="95%" style="left: 0px; top: 0px;" classid="clsid:E77E049B-23FC-4DB8-B756-60529A35FAD5"
- codebase="/ocx/WebOffice.cab#V6,0,5,0">
- <param name="_ExtentX" value="6350" />
- <param name="_ExtentY" value="6350" />
- </object>
- <![endif]-->
- <!--[if !IE]> -->
- <object id="Control"
- TYPE="application/x-itst-activex"
- ALIGN="baseline" BORDER="0"
- WIDTH="95%"HEIGHT="600px"
- clsid="{E77E049B-23FC-4DB8-B756-60529A35FAD5}"
- event_NotifyCtrlReady="NotifyCtrlReady"
- event_NotifyToolBarClick="NotifyToolBarClick"
- event_NotifyWordEvent="NotifyWordEvent">
- </object>
- <!-- <![endif]-->
另外一种兼容性:IE的版本兼容
<head> <meta http-equiv="X-UA-Compatible"
content="IE=9;IE=8;IE=7"></head>