开发者

Android/Java - Find text and replace in WebViewClient

开发者 https://www.devze.com 2023-04-08 09:14 出处:网络
I have a WebViewClient that opens in a dialog which i can capture when the URL changes, but on certain URL\'s I would like to replace certain text but I cant seem to figure out how to get the text of

I have a WebViewClient that opens in a dialog which i can capture when the URL changes, but on certain URL's I would like to replace certain text but I cant seem to figure out how to get the text of the current webpage that has been loaded so I can search 开发者_如何转开发and replace that text.


Looks like there is already a question about getting the HTML code from a WebView. Please take a look at that: Is it possible to get the HTML code from WebView (Main tutorial is here: http://lexandera.com/2009/01/extracting-html-from-a-webview/)

Of course, once you get the HTML code (string) you can do anything that you want such as replacing the text as you wanted!

Manipulated HTML string can be loaded into the view with following code snippet:

webview.loadData(newHtmlStr, "text/html", "utf-8");

newHtmlStr is the new data and it must be URI-escaped!

0

精彩评论

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