无法在 UIWebView 中加载 javascript
Can't load javascript in UIWebView
我正在尝试加载 javascript 文件,但它不起作用。
我的代码:
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];
此代码本应显示视频,但没有任何反应。
此代码在桌面浏览器中正确显示视频,我的 JS 是正确的。
不要使用字符串描述。而是使用:
[_webView loadHTMLString:html baseURL:nil];
在- webViewDidFinishLoad:
中写入如下代码
NSString * strJavaScript = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://mywebsite.com/file.js"] encoding:NSUTF8StringEncoding error:nil];
[_webView stringByEvaluatingJavaScriptFromString:strJavaScript];
在 baseURL
中使用 url
NSURL *base=[NSURL URLWithString:@"website.com"];
我正在尝试加载 javascript 文件,但它不起作用。
我的代码:
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];
此代码本应显示视频,但没有任何反应。 此代码在桌面浏览器中正确显示视频,我的 JS 是正确的。
不要使用字符串描述。而是使用:
[_webView loadHTMLString:html baseURL:nil];
在- webViewDidFinishLoad:
中写入如下代码
NSString * strJavaScript = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://mywebsite.com/file.js"] encoding:NSUTF8StringEncoding error:nil];
[_webView stringByEvaluatingJavaScriptFromString:strJavaScript];
在 baseURL
中使用 urlNSURL *base=[NSURL URLWithString:@"website.com"];