如何让用户在用webview访问网页时嵌入我们自己的内容

代码如下:
        NSString *strUrl=[textField text];
    NSString *urlString=[NSString stringWithFormat:strUrl];
    NSURL *url=[NSURL URLWithString:urlString];
    NSURLRequest *urlRequest=[NSURLRequest requestWithURL:url
                                              cachePolicy:NSURLRequestReturnCacheDataElseLoad
                                          timeoutInterval:60];
    NSData *urlData;
    NSURLResponse *response;
    NSError *error;
    urlData=[NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];
    NSString *dataStr =[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
    dataStr = [dataStr substringToIndex:[dataStr length] - 16];
    dataStr = [dataStr stringByAppendingString:@"<p>hello world navy did it </p></body></html>"];
    NSLog(@"%@",dataStr);
    const char *cString = [dataStr UTF8String];
    NSData *myData= [[NSData alloc]initWithBytes:cString length:strlen(cString)+1];
    [self.myWebView loadData:myData MIMEType:@"text/html" textEncodingName:@"utf-8" baseURL:url];

这个代码我是在UICatalog中WebViewController中添加的,有人要这功能,小生就乘机学习了下,嫌麻烦,直接用的UICatalog代码.见谅.
此代码功能在于:在你访问的网页左下角加了hello world navy did it.几个字.
不希望做流氓功能.一切以用户为主.

 

如何让用户在用webview访问网页时嵌入我们自己的内容,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。