1

I have a UIWebView and I load a local page that references a local CSS stylesheet. My app has the ability to let the user adjust the font size within the app, and so I want this to apply to the font size for local web pages that I show within the app too.

I know that I can inject javascript into a webview using stringByEvaluatingJavaScriptFromString.

How can I use Javascript to modify the font size for my HTML document?

1 Answer 1

1

In the UIWebView delegate method webViewDidFinishLoad you can try this:

NSString *fontSize=@"14";
NSString *jsString = [[NSString alloc]      initWithFormat:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '%d%%'",[fontSize intValue]];
[myWebview stringByEvaluatingJavaScriptFromString:jsString];

This adds JavaScript, as you mentioned, to adjust the font size to 14.

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.