0

I am trying to print HTML with this JavaScript in the webview, however it is literally printing <p>HELLO</p>. How can I fix that?

NSString* statement = [NSString stringWithFormat:@"document.getElementById('test').innerText = '<p>HELLO</p>'"];

[self.myWebView stringByEvaluatingJavaScriptFromString:statement];
LuckyLuke
  • 47,771
  • 85
  • 270
  • 434
  • http://stackoverflow.com/questions/992348/reading-html-content-from-a-uiwebview just check whether it is helping – hacker Jun 21 '12 at 06:57

1 Answers1

3

I guess you need to use innerHTML instead of innerText.

Because innerText will simply assign whatever you write there. If your text contains html and you element parse that HTML than you have to use innerHTML for sure.

Try as follow, may be it will help.

NSString* statement = [NSString stringWithFormat:@"document.getElementById('test').innerHTML = '<p>HELLO</p>'"];    
[self.myWebView stringByEvaluatingJavaScriptFromString:statement];

Note Your test element must be supporting innerHTML property like div span etc.

Janak Nirmal
  • 22,706
  • 18
  • 63
  • 99