1. How to disable the webview could scroll.
[(UIScrollView *)[[_webView subviews] objectAtIndex:0] setBounces:NO];
2. Get the html title for webview content.
Using JavaScript:
NSString *htmlTitle = [_webView stringByEvaluatingJavaScriptFromString:@"document.title"];
3. Support the UITouch Event.
Using JavaScript:
#define WebTouchJavaScript @"<script language="javascript">document.ontouchstart=function(){document.location="myweb:touch:start";}; document.ontouchend=function(){document.location="myweb:touch:end";};document.ontouchmove=function(){document.location="myweb:touch:move";}</script>"
the webview will load the html string, using this java script between the <body> and </body>.
Then, method: [_webView loadHTMLString: baseURL: ] to load. And then the web view could support the UITouch event.
The delegaete method to judge which touch event is occur.
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request
navigationType:(UIWebViewNavigationType)navigationType {
NSString *requestString = [[request URL] absoluteString];
NSArray *components = [requestString componentsSeparatedByString:@":"];
if ([components count] > 1 &&
[(NSString *)[components objectAtIndex:0] isEqualToString:@"myweb"]) {
if([(NSString *)[components objectAtIndex:1] isEqualToString:@"touch"]) {
//Dispatch the UITouch Event and handle with reference actions.
NSLog(@"touch : %@", [components objectAtIndex:2]);
4,禁止选中文本
[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];