现在的位置: 首页 > 综合 > 正文

UIWebView about some properties

2013年09月10日 ⁄ 综合 ⁄ 共 1560字 ⁄ 字号 评论关闭

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';"];

抱歉!评论已关闭.