javascript - Unable to highlight text in UIWebview? -
i have been working on highlighting text in uiwebview. in used canperformaction method in call javascript function highlight text. lets take text in webview "the part confusing , sporadic". here if select text "so" alone there no problem , highlighting text.
but lets take select more 1 word "so confusing and" highlights runs in infinite loop , keep on calling canperformaction method. not figure out why happening.
in ipad if long press on text selected. method gets called here , highlights selected text. if drag blue lines select further text (i hope u can understand saying) in canperformaction called , runs infinite loop.
i checking in simulator.
updated: tried things have told follows
nsstring *selectedstring = @"function getseltext()" "{" "alert('document.execute');" "var sel = window.getselection();" "if(!sel.iscollapsed){" "var selrange = sel.getrangeat(0);" "document.designmode = 'on';" "sel.removeallranges();" "sel.addrange(selrange);" "alert('document.execute 2');" "document.execcommand('hilitecolor', false, '#ffffcc');" "alert('document.execute 3');" "sel.removeallranges();" "document.designmode = 'off';" "alert('document.execute 4');" "}" "}"; [webview stringbyevaluatingjavascriptfromstring:selectedstring]; have given above code in webviewdidfinishload. in canperformaction gave -(bool)canperformaction:(sel)action withsender:(id)sender { if(action == @selector(selectall:)){ nsstring *sethighlightcolorruling = [nsstring stringwithformat:@"getseltext()"]; [webview stringbyevaluatingjavascriptfromstring:sethighlightcolorruling]; return yes; } return [super canperformaction:action withsender:sender]; } while running in simulator alert till last "document.execute 4" appearing there no effect in webview
Comments
Post a Comment