Hello. When displaying a page in UIWebView, you must select parts of the text. This is done using the stringByEvaluatingJavaScriptFromString method and javascript, which inserts the necessary context into the "span" tags with the required style and eventually changes document.body.innerHTML. However, there is a situation when document.body.innerHTML changes as needed, and this can be seen at the output of stringByEvaluatingJavaScriptFromString, and the WebView component does not show these changes. How to deal with it?
js = @"\ body_inner_html = document.body.innerHTML;\ var __search = '%@';\ var __a;\ var __re;\ var i,k;\ __re = new RegExp('('+__search+')','gi');\ __a = document.getElementsByTagName('*');\ for (i = 0; i < __a.length; i++) {\ for (k=0; k<__a[i].childNodes.length; k++) {\ if (__a[i].childNodes[k].nodeType == 3) {\ __a[i].childNodes[k].textContent = __a[i].childNodes[k].textContent.replace(__re,'searchres$1');\ }\ }\ }\ var __s;\ __re = new RegExp('(searchres'+__search+')','gi');\ __s = document.body.innerHTML.replace(__re,'<span style=\"background-color:#e0e0e0;\">$1</span>');\ __re = new RegExp('searchres','g');\ __s = __s.replace(__re,'');\ document.body.innerHTML = __s;\ "; expr = [NSString stringWithFormat:js,search_context_value]; [webview1 stringByEvaluatingJavaScriptFromString:expr];