In my application , i have to change font from webPage that loaded from online.
First i store my CustomJava.js files in online hosting and i use that file to change font in my iOS app.
Here is some of my codes.
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
NSString *js = [NSString stringWithFormat:@"var script = document.createElement('script');"
"script.type = 'text/javascript';"
"script.src = 'http://www.gustohei.com/SYjs/customJava.js';"];
js = [NSString stringWithFormat:@"%@ document.getElementsByTagName('head')[0].appendChild(script);", js];
[self.webViewOfBrowser stringByEvaluatingJavaScriptFromString:js];
UIApplication *app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = NO;
}
It's fine and change font correctly.
In my case , i want to keep that JS File in my document directory and want to use that file from document directory . i don't want to use from online.
So i wrote following code.
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
NSString *jsPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"customJava.js"];
NSString *js = [NSString stringWithFormat:@"var script = document.createElement('script');"
"script.type = 'text/javascript';"
"script.src ='%@'",jsPath];
js = [NSString stringWithFormat:@"%@ document.getElementsByTagName('head')[0].appendChild(script);", js];
[self.webViewOfBrowser stringByEvaluatingJavaScriptFromString:js];
UIApplication *app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = NO;
}
However it's doesn't work. How to do that?