如何让用户在用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访问网页时嵌入我们自己的内容,布布扣,bubuko.com

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

上一篇:【CSS3】Advanced9:Transformation


下一篇:Js仿弹框