I want to create a bookmarklet that will search for a text and replace with a hyperlink
So, I want to search for a text (say "wikipedia") and have all the "wikipedia" in the page turn into a开发者_JAVA技巧 link that redirects to wikipedia.
Thanks!
I wouldnt do this by using the solution linked by VoteyDisciple, walking all elements could take a long time, and replacing innerHTML could lead you to unwanted results, while this will not only access TextNodes.
I would prefer textRanges to do this.
in MSIE: find the string with findText() and replace it using pasteHTML
in others(except opera): find the string with window.find() and surround it using surroundContents()
For opera I actually dont know a method how to find text, maybe there is an opera-specific method available.
精彩评论