开发者

I want to create a bookmarklet that will search for a text and replace with a hyperlink

开发者 https://www.devze.com 2023-01-22 03:22 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消