Javascript programming principles that WebOffice beginners must know (1)

The WebOffice control is the leading online editing Office document software in China. The software product has a history of more than 20 years since its establishment in 1998, and has served many large, medium and small enterprises, government agencies at all levels, scientific research institutions, schools and other institutions. Through the WebOffice software, users can conveniently open Word, Excel, Ppt and other documents remotely and save them to the original location of the server after editing, realizing remote editing and remote saving, and creating an innovative and convenient experience for users in online office.

Huidu.com downloads the official version of WebOffice for free

Documentation instructions:

This document comprehensively introduces how the WEB front-end integrates WebOffice controls, realizes the call of control functional interfaces through Javascript programming, and achieves the purpose of solving the needs of Web projects. After mastering this front-end design, you will understand the solution of WebOffice at the View layer to suit any Web project architecture. .

This document is suitable for first-time users of WebOffice to learn and use. The following computer technology languages ​​are required to study this article: HTML, Javascript

1. Javascript programming principle

1.1. Load WebOffice in the web page and obtain the programming object and store it in the specified variable

Download the WebOffice.rar installation package, install the WebOffice components locally, load the control on the web page

The following is the control loading code, these codes are fixed, just put it in the corresponding position of your webpage.

<script language="javascript">
if (!!window.ActiveXObject || "ActiveXObject" in window){
document.write('<object classid="clsid:FF09E4FA-BFAA-486E-ACB4-86EB0AE875D5" codebase="WebOffice .ocx#Version=2019,1,7,3" id="WebOffice" width="900" height="500" >');
document.write('</object>');}
else
{
document.write ('<object id="WebOffice" CLSID="{FF09E4FA-BFAA-486E-ACB4-86EB0AE875D5}" TYPE="application/x-itst-activex" width=100% height=900></object>');
}
</script>
Place the control object through the above JS code. The name of the control object is defined by the ID attribute above, which is: WebOffice. In this way, the following code can be used to access the WebOffice control in the JS code:
var obj = document.getElementById('WebOffice ');

运行上面此句后,则obj即为Javascript编程对象。大多数情况下建议对象名称统一为:WebOffice,即用下面代码获得控件对象:

var WebOffice = document.getElementById('WebOffice');

The variable weboffice of the above JS statement is the JS programming object of the control

1.2, use the WebOffice object to access the control interface

When the control is loaded normally, you will see the interface displayed by the control, as shown in the figure below, which means that the control is loaded normally

Javascript programming principles that WebOffice beginners must know (1)

The figure above is the interface after the control is running.

When the control is loaded normally, use the JS code to obtain the control programming object and then call the control related methods to meet the requirements. For example, use the OPEN method to open a specified WORD document, such as the following code:

var WebOffice=document.getElementById("WebOffice");
WebOffice.Open(' http://www.officectrl.com/officecs/temp/word.doc ');
1.3. After the web page is loaded, the specified document is automatically opened to
realize the web page loading After the control is automatically opened, the Open method is executed in the ONLOAD event of the BODY tag of the webpage, and a short delay processing function is added before the Open method is executed to facilitate the browser to execute the Open method after the control is fully loaded.

Add the function name: webopen to the onload event of the web page tag body, the code is as follows:

<body topmargin=0 leftmargin=0 onload="javascript:WebOpen();">

In the Webopen function, implement the delayed response execution of the JS function OpenDocument, and execute the Open method in this function OpenDocument. The implementation of the JavaScript function is as follows:
<script language=javascript>

function WebOpen()

{

   WebOffice = document.getElementById('WebOffice');//获得控件对象

   if (WebOffice){//等待控件初始化完毕,时间可以根据网络速度设定。

         setTimeout('OpenDocument()',1000);}  //1000代表1秒后执行

}

function OpenDocument()

{

   try{

          var strOpenUrl = ‘http://www.officectrl.com/officecs/temp/word.doc’;  

          document.getElementById('WebOffice').Open(strOpenUrl,true,"Word.Document");

   }catch(e) {

alert (e);

   }

}

</script>
If you want to purchase a genuine WebOffice license, or for more product information, please click [Consult Online Customer Service]

If you want to know about Gantt chart or Huidu APS system, please log in to Huidu.com and consult online customer service to solve your problem!
This article is reproduced from [Huidu Technology] evget welcomes any form of reprinting, but please be sure to indicate the source, do not modify the relevant links of the original text, and respect the achievements of others’ labor

Guess you like

Origin blog.51cto.com/14874181/2550327