Skip to main content
PedroSaraiva
Participating Frequently
December 1, 2023
Question

Temporarily highlight a specific text after clicking the link to it (using Javascript)

  • December 1, 2023
  • 1 reply
  • 1739 views

Hi!

 

I got a scientific paper with many bibliographical references.

It would be useful if readers after clicking an author's year not only got redirected to the page's reference, but that same reference could be temporarily highlited.

 

For example: text text text (Goetze, 2016)

After clicking the link (2016) the reader is redirected to the page where the complete bibliographical reference is, in this case:

GOETZE, C. (2016). Warlords and States: A Contemporary Myth of the International System. In B. B. de Guevara (Ed.), Myth and Narrative in International Politics: Interpretive Approaches to the Study of IR (pp. 129–146). Palgrave Macmillan.

 

Since there are a lot o references in the same page it would useful if it got temporarily highlited.

Is it possible to do this using Javascript?

 

Thanks

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
December 1, 2023

It is, but it's quite tricky to implement. One option would be to select the first word in the reference, but you'll have to hard-code the word's index for each link.

Another option is to create a Highlight comment for each link, set it as hidden, and then show it when the link is clicked. Then use a TimeOut object (via app.setTimeOut) to hide it again after the desired amount of time.

PedroSaraiva
Participating Frequently
December 2, 2023

Thanks @try67!

The 2nd option is not what I want.

 

Could you elaborate on the 1st option? I'm new to using Javascript in Acrobat... 😅

try67
Community Expert
Community Expert
December 2, 2023

Sure. You can use the selectPageNthWord method for that.

For example, this will select word #21 on page 2 (both values are zero-based):

this.selectPageNthWord(1, 20);

To find out which word index to use you would need to print out the whole page's contents and then look for it. You can do that using this code from the JS Console (this will print the current page's text):

 

var p = this.pageNum;
var numWords = this.getPageNumWords(p);
for (var i=0; i<numWords; i++) {
	var word = this.getPageNthWord(p,i,true);
	console.println(i+":"+word);
}