File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes open MSWord document through Javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "open MSWord document through Javascript" Watch "open MSWord document through Javascript" New topic
Author

open MSWord document through Javascript

shalu pareek
Greenhorn

Joined: Nov 14, 2008
Posts: 14
Here is my code which will open MSWord document through java script.

In IE it works fine but in Mozilla firefox its throwing me some error like ActiveX object is not defined.


<script language="JAVASCRIPT" type="TEXT/JAVASCRIPT">



function Comp_action()
{ var url = document.Actiontab.selectcomp.options[document.Actiontab.selectcomp.selectedIndex].value

if (url=="E")
{ alert("hello")

var word=new ActiveXObject('Word.Application');
var docText;
var obj;
word.Visible = true;
// String abc="";
obj= word.Documents.Open("C:\\A.xml");

alert("hello2")

}//if
else { } //else


}


</SCRIPT>

Please help to open MSWord doc threw Firefox also. Is Mozilla doesnt support Active Xobject.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39551
    
  27
Hello "sush sush"-

Welcome to JavaRanch.

On your way in you may have missed that we have a policy on screen names here at JavaRanch. Basically, it must consist of a first name, a space, and a last name, and not be obviously fictitious. Since yours does not conform with it, please take a moment to change it, which you can do right here.

As to your question, no browser but IE supports ActiveXObject, so you're limited to one particular browser on one particular operating system. Why not just link to the document, and let the user decide what to do with it (open it with some application, or save it to disk)?


Ping & DNS - updated with new look and Ping home screen widget
shalu pareek
Greenhorn

Joined: Nov 14, 2008
Posts: 14
Hi thanks for the quick replay but my problem is i have to launch the MSoffice plugin XA which is xml editor. But it will lauch in similar way as MSoffice doc document. So here wht we are trying to do is we will let clients to open the doc and edit and it will get save in server itself.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Before you post again, please change you display name.

window.open("foo.doc") or window.location.href="foo.doc"; will open the doc in word if the user has their computer set up right.

Other than that you have no control.
shalu pareek
Greenhorn

Joined: Nov 14, 2008
Posts: 14
Thanks the script works fine in IE but it wont work in FireFox.

Its showing me this error:

ActiveXObject is not defined
var word=new ActiveXObject('Word.Application');
Could you please provide me the solution for this.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39551
    
  27
Like I said, ActiveXObject only works in IE.
shalu pareek
Greenhorn

Joined: Nov 14, 2008
Posts: 14
do you any remedy for that . Wht else i can use so as to open a document in the server to the client side.
Is there any other method in java script which will open word document.

Intead of ActiveX Control wht i can use?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39551
    
  27
Originally posted by Ulf Dittmer:
Why not just link to the document, and let the user decide what to do with it (open it with some application, or save it to disk)?
shalu pareek
Greenhorn

Joined: Nov 14, 2008
Posts: 14
Hi,
My requirement is to open the doc at server side in MSoffice only. Basically wht i am trying to achieve over here is to launch MSOffice at the cleint side frm my appliaction.
I am wroking in Content mangagemenet. So once the doc had been opened i need to save back changes which user had made to the server also. Tht will be later requirement. WE are using XA which is MSoffice plugin to open xml doc.
So basically i have to open MSOffice.
Please let me how to do that. I dnt understand how we can just provide a link to the doc and let user to decide to open tht.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39551
    
  27
I dnt understand how we can just provide a link to the doc and let user to decide to open tht.

That's simple: <a href="my-word-file.doc">my Word document</a>

If the user clicks on that, she will be prompted what to do with it - open it (with a choice of which application to use), or save it to disk. In that dialog is an option to let the user specify that Word documents should always be opened by a particular application; if chosen, the dialog will then never be shown again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: open MSWord document through Javascript
 
Similar Threads
JavaScript Compatibility with Mozilla
XMLHtmlRequest return Undefine
ALT Key Combination help.
preview of an image for uploading in firefox
Enter Key event working fine in IE but not FireFox.