please view the attached image for output
this is the code I have written in js
Office.context.document.addHandlerAsync(
Office.EventType.DocumentSelectionChanged,
(result: any) => {
let bookmark = localStorage.getItem("bookmark")
let bookmarkParse = JSON.parse(bookmark);
console.log("bookmarkParse",bookmarkParse)
bookmarkParse.map((item: any) => {
Word.run(async (context) => {
console.log("result", result);
const range = context.document.getSelection();
console.log("getRange",range)
return context.sync().then(async function ()
{
context.load(range);
await context.sync();
let text = range.text
console.log("item", item.ImageId, text);
if (item.ImageId == text) {
console.log("item bookmark",item.bookmark)
range.hyperlink = "#" + item.bookmark;
console.log("range.hyperlink",range.hyperlink)
console.log(item.bookmark,"range matched");
} else {
console.log("range not matched");
}
await context.sync();
});
here is the my code for redirected to image when clicking on the test.