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];
1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.