0

I use the code to load a request

[self.webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.wezeit.com/contentClient.php?postId=76949"]]];

and i use the code below to underline the text

- (void)note:(id)sender{
     NSString *result = [self stringByEvaluatingJavaScriptFromString:@"document.execCommand(\"Underline\")"];
     NSLog(@"result %@",result);
}

but it doesn't work. Why?

X-Istence
  • 16,324
  • 6
  • 57
  • 74
iWenPro
  • 49
  • 6
  • Maybe your javascript was executed (and failed because it couldn't find the element to underline) before your webpage finished loading the content. I think UIWebView has a callback method `- (void)webViewDidFinishLoad:(UIWebView *)webView` ( https://developer.apple.com/library/ios/documentation/Uikit/reference/UIWebViewDelegate_Protocol/index.html#//apple_ref/occ/intfm/UIWebViewDelegate/webViewDidFinishLoad: ) for when it finished loading the page, maybe execute your javascript there. – Zhang Nov 06 '14 at 06:43
  • hi, I confirm the web view finished loaded. because the note method above,is my custom uimenuitem handler. – iWenPro Nov 06 '14 at 07:01
  • I'm not sure if this helps but someone mentions that the function call should looks like `document.execCommand(command, uiBool, argument)` maybe you're missing the other two parameters. Explanation here: http://stackoverflow.com/questions/1817441/javascript-document-execcommand-cross-browser Perhaps you also need to do: `document.getElementById("whateverID").document.execCommand('underline', false, null);` – Zhang Nov 06 '14 at 07:08
  • this help me out, code like below ` [self stringByEvaluatingJavaScriptFromString:@"document.body.contentEditable ='true';" " document.execCommand(\"Underline\");" "document.body.contentEditable ='false';"];` but it shows a bottom bar that i don't need it ,how can hide it? – iWenPro Nov 06 '14 at 07:27

0 Answers0