iOS WebView 的一些实用方法
2016-07-08 本文已影响207人
云深不知处a
1、给webView 添加手势方法
ios 5以后要重写这个方法并加上手势协议才能点击 把协议委托给控制器 在webView上加手势
UIWebViewDelegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
return YES;
}
2、获取webView的高度
-(void)webViewDidFinishLoad:(UIWebView *)webView{
int webViewHeight = [[webView stringByEvaluatingJavaScriptFromString: @"document.documentElement.scrollHeight"] intValue];
}
3、获取标题、当前页面的URL
NSString*currentURL=[webViewstringByEvaluatingJavaScriptFromString:@"document.location.href"];
NSString*title=[webviewstringByEvaluatingJavaScriptFromString:@"document.title"];
4、修改界面元素的值
NSString*js_result=[webViewstringByEvaluatingJavaScriptFromString:@"document.getElementsByName('q')[0].value='中国';"];