Ios:webview Inside Highlight Search

Source: Internet
Author: User

Because WebView load is the Web page can only be used to search the page with JS nonsense do not say on the code

//Inject JS SearchNSString *respath =[[NSBundle Mainbundle] resourcepath]; StaticNSString *jsquery =Nil; Staticdispatch_once_t Oncetoken; Dispatch_once (&oncetoken, ^{jsquery= [NSString Stringwithcontentsoffile:[respath stringbyappendingpathcomponent:@"Js_plugins.js"] encoding:nsutf8stringencoding Error:nil];    }); NSString*js = [NSString stringWithFormat:@"var highlightplugin = document.getElementById (' js_plugins '); if (Highlightplugin = = undefined) {Document.body.innerHTML + = ' <div id=\"Js_plugins\"> \<style type=\"text/css\ "> \. utahighlight {background-Color:yellow;} . selectspan {Background-color:yellow; color:red;} </style>                     </div>'; \%@                     }", Jsquery];[self stringbyevaluatingjavascriptfromstring:js]; //clears the last highlight and sets the current keyword highlighting[Self stringbyevaluatingjavascriptfromstring:[nsstring stringWithFormat:@"jQuery (' body '). Removehighlight (). Utahighlight ('%@ ');", str]]; //get the number of keywordsNSString *count = [Self stringbyevaluatingjavascriptfromstring:@"jQuery ('. Utahighlight '). Length"]; if([Count Integervalue]>0) {[Self Focustofindindex:0]; }
dispatch_once Use a single case without having to read the file once per call, followed by some methods of invoking some JS files.
Extensible previous next, not implemented for the time being.
Other specific file methods can be seen in demo
Http://pan.baidu.com/s/1eQAGNPC

Ios:webview Inside Highlight Search

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.