0

I initialize a UIWebView as follows:

NSString *msg = <HTML><BODY bgcolor=\"#504a4b\" style=\"font-family:Verdana; font-size:20\" > <B> No Messages";
[webviewMessageLog loadHTMLString:msg baseURL:NULL];

which shows the text exactly as I expect. Later, I want to append to this log. As a test, I did:

-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    NSString *oldHTML = [webviewMessageLog stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML"];
    NSLog(@"%@", oldHTML);

this returns the HTML starting after the tag, like such:

 <b> No Messages</b>

My question is: what javascript object do I need to read to see the parameters I set within the BODY tag? How would I see the font-family and bgcolor items that were previously set? I want to maintain whatever formatting had been set elsewhere, and I'm hoping to just read the prior BODY tag and avoid additional code to re-evaluate what the BODY tag should include.

Thanks!

Thunk
  • 4,099
  • 7
  • 28
  • 47

1 Answers1

0

If you want to get the bgcolor attribute, you can use:

NSString *bgColor = [webviewMessageLog stringByEvaluatingJavaScriptFromString:@"document.body.getAttribute("bgcolor")"];
NSLog(@"%@", bgColor);

Similar like, you can access the other attributes too.

Midhun MP
  • 103,496
  • 31
  • 153
  • 200
  • Thanks! So I will have to query each potential element since I won't necessarily know what would have been set? There's no way to just pull the entire contents of the body tag into an NSString? – Thunk Jan 02 '15 at 07:43
  • @Thunk: check this : http://stackoverflow.com/questions/2048720/get-all-attributes-from-a-html-element-with-javascript-jquery – Midhun MP Jan 02 '15 at 07:49