This article mainly introduces how to open a Word document in javascript. For more information, see create an html file and write a FileUpLoad and button control.
The Code is as follows:
The Code is as follows:
FileUpload
Then, write a javascript OpenFile method.
The Code is as follows:
The Code is as follows:
Function OpenFile ()
{
If (document. getElementById ("flUpload"). value. toUpperCase (). indexOf (". XLS ")! =-1)
{
Var objExcel;
ObjExcel = new ActiveXObject ("Excel. Application ");
ObjExcel. Visible = true;
ObjExcel. Workbooks. Open (document. getElementById ("flUpload"). value );
}
Else if (document. getElementById ("flUpload"). value. toUpperCase (). indexOf (". DOC ")! =-1)
{
Var objDoc;
ObjDoc = new ActiveXObject ("Word. Application ");
ObjDoc. Visible = true;
ObjDoc. Documents. Open (document. getElementById ("fileUpload"). value );
}
Else
{
Alert ("Please select Word/Excel file only ");
Return false;
}
}
OK. Then, you can select a Word document in IE and click open to open the Word document.
Is it very simple? It seems that it can only be used in IE.