Reputation: 649
I'm trying to load a javascript file but it doesn't work.
My code :
NSString *html = [NSString stringWithFormat:@"<html><head></head><body><script type=\"text/javascript\" src=\"http://mywebsite.com/file.js\"></script></body></html>"];
[_webView loadHTMLString:html baseURL:nil];
This code is supposed to display a video, but nothing happens. This code displays correctly the video in Desktop browser, my JS is correct.
Upvotes: 1
Views: 2717
Reputation: 1477
use url in baseURL
NSURL *base=[NSURL URLWithString:@"website.com"];
Upvotes: 4
Reputation: 6342
Write following code in - webViewDidFinishLoad:
NSString * strJavaScript = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://mywebsite.com/file.js"] encoding:NSUTF8StringEncoding error:nil];
[_webView stringByEvaluatingJavaScriptFromString:strJavaScript];
Upvotes: 0
Reputation: 3628
Do not use string description. Instead use:
[_webView loadHTMLString:html baseURL:nil];
Upvotes: 0