Find word in HTML page fast algorithm

后端 未结 2 1903
我在风中等你
我在风中等你 2021-01-13 04:37

I need to do a boolean function which returns true if a word is in the text of a HTML page and false if it\'s not.

I know that it\'s easy to do analysing all the pa

2条回答
  •  星月不相逢
    2021-01-13 05:20

    I'd get the entire page as a string:

    var markup = document.documentElement.innerHTML;
    

    And, then I'd use a method to search for the string in a string:

    var n = markup.search("YourString");
    

    You'll get a number for the index of the match or -1 if no match found.

提交回复
热议问题