javascript - Retrieving HTML-tags from UIWebview using -


i'm developing custom webview on ios should give users special options when selecting elements on webpage, therefor i'm extending uiwebview , adding own buttons sharedmenucontroller. because page shown made xml using xsl style it, there data in tags, e.g.

<p data-type="mc"><img src="annotation.png"></p> 

when selecting image, sharedmenucontroller pops up, , if press action button, receive tag containing img tag. problem using window.getselection().innerhtml.tostring() gives me empty string , window.getselection().getrangeat(0).commonancestorcontainer.innerhtml.tostring() should p-tag, gives me entire html.

this class:

@implementation uicustomwebview  + (void)initialize {     [super initialize];     uimenuitem *itema = [[uimenuitem alloc] initwithtitle:@"action" action:@selector(a:)];     [[uimenucontroller sharedmenucontroller] setmenuitems:[nsarray arraywithobjects:itema, nil]];     }  -(bool)canperformaction:(sel)action withsender:(id)sender {         if (action == @selector(defineselection:))     {         return yes;     }     else if (action == @selector(translateselection:))     {         return yes;     }     else if (action == @selector(copy:))     {         return no;     }     else if ( action == @selector( a: ) )     {         return yes;     }      return [super canperformaction:action withsender:sender]; }  -(void) a:(id)sender {     nslog(@"a %@", [self stringbyevaluatingjavascriptfromstring:@"window.getselection().getrangeat(0).commonancestorcontainer.innerhtml.tostring()"]); } @end 

try this:

 nsstring *htmlstring=[[webview stringbyevaluatingjavascriptfromstring:@"getselectionhtml()"]mutablecopy]; 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -