iOS开发之获取webView的内容等(JS交互)

1.在.h文件定义

   @property (strong,nonatomic)UIWebView *webView;
    @property (strong,nonatomic)NSString *currentURL;
    @property (strong,nonatomic)NSString *currentTitle;
    @property (strong,nonatomic)NSString *currentHTML;

2.在.m文件执行

  -(void) webViewDidFinishLoad:(UIWebView *)webView {
    [UIApplicationsharedApplication].networkActivityIndicatorVisible =NO;
    self.title = [webViewstringByEvaluatingJavaScriptFromString:@"document.title"];//获取当前页面的title

    self.currentURL = webView.request.URL.absoluteString;
    NSLog(@"title-%@--url-%@--",self.title,self.currentURL);

    NSString *lJs = @"document.documentElement.innerHTML";//获取当前网页的html

    self.currentHTML = [webView stringByEvaluatingJavaScriptFromString:lJs];
    }

你可能感兴趣的:(iOS开发之获取webView的内容等(JS交互))