JavaScript:在页面上查找特定单词

问题描述 投票:-5回答:1

我正在尝试找到一种方法,以在网站中找到特定的单词或短语,然后在找到单词时弹出“提示”。困难的部分是我需要在一个书签中完成所有这些操作。

我正在尝试在一个我不拥有的网站上使用它,以便于我进行研究。有人知道该怎么做吗?

javascript arrays alert
1个回答
0
投票

假设您正在网站中搜索特定词。您可以使用说的话

   let text = document.body.innerText; // To get the content of the page as a string
  text=text.toLowerCase(); // formatting them both in lower case for easy match
  phrase = phrase.toLowerCase();
   if(text.indexOf(phrase)>=0) { // where phrase represents your word or group of words as a string
      console.log('Phrase found');
  }
© www.soinside.com 2019 - 2024. All rights reserved.