How to write a 'field' as link in microsoft word addin using javascript API

344 views Asked by At

I would like to have a javascript (Microsoft Word-API) equivalent code of the following C# code snippet:

Field field = Application.ActiveDocument.Fields.Add(Application.Selection.Range, WdFieldType.wdFieldLink, LinkText);

if (field != null) {
    field.Update();
}

In other words, I want to add a field code in the microsoft word addin (2016) document using javascript API.
After thorough searching all over the internet, I found a 'stackoverflow' question (How do we add field code for Word using word javascript api) that asks the same. But the problem is, there is no concrete answer in this post. There is only 1 answer and it states that "There is no direct support in the API for adding fields, i.e. you will have to create Open XML containing the field". Now the thing is when I tried to look at the documentation of Open XML : https://msdn.microsoft.com/en-us/library/dd721893%28v=office.12%29.aspx?f=255&MSPPError=-2147217396 , i get to know that it is totally obsolete! (the first line is "This content is outdated and is no longer being maintained").

Furthermore, i think converting the string 'LinkText' to a link (in javascript) can be an alternative to this problem. But I really want to know if there are other alternatives because the link() method (in javascript) is not standard, and may not work as expected in all browsers (reference: http://www.w3schools.com/jsref/jsref_link.asp).

0

There are 0 answers