在webView的代理方法中- (void)webViewDidFinishLoad:(UIWebView *)webView
同过JS于OC交互获取
#pragma WebViewDelegate
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
NSString *JsToGetHTMLSource = @"document.getElementsByTagName('html')[0].innerHTML";
NSString *HTMLSource = [webView stringByEvaluatingJavaScriptFromString:JsToGetHTMLSource];
NSLog(@"%@",HTMLSource);
}
下面还有一些常用的
- 获取页面title
NSString *title = [webview stringByEvaluatingJavaScriptFromString:@"document.title"];
- 获取当前的URL
NSString *url = [webview stringByEvaluatingJavaScriptFromString:@"document.location.href"];
网友评论