0

I am writing chrome extension. My purpose is when someone clicks on a word in any page, I want to get that sentence in my code. I have found getClick function for chrome extension, but I do not know how to get the sentence which involves the clicked word? Or maybe there exists any other ways to do this? Thanks!!!

  • Welcome to Stack Overflow! Please review [Writing the perfect question](https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question) to help you to ask a good question, and thus get a good answer. – Jeroen Heier Aug 07 '18 at 17:14

1 Answers1

0

here is a similar problem that was solved: Detect which word has been clicked on within a text

your can also try defining your own function on a span in case there is a specific word you want to identify when clicked on attach your function this way: onclick = myfunction(this) this will hold all the information you need

if you will explain your question with more details I may be able to help you a bit more

Amit Biran
  • 16
  • 3
  • Thanks! What I want is for example, someone is browsing on this website https://en.wikipedia.org/wiki/Atlantic_Ocean, and clicks on the word "kilometers" in the first sentence of the page. Then I want to get the whole sentence "The Atlantic Ocean is the second largest of the world's oceans, with an area of about 106,460,000 square kilometers (41,100,000 square miles)." – İpek Uyguner Aug 07 '18 at 19:05
  • there may be a more elegant solution from what im about to propose, and ill try to think of one and will write it here but for now this is what i can think of from the back of my head: scrape the

    elements inside the page, and insert a span that contains each sentence in the p element. for each span give a function that will display its innerHTML upon clicking it. makes sense?

    – Amit Biran Aug 07 '18 at 19:41