Opening popup links in UIWebView, possible?

前端 未结 4 972
旧时难觅i
旧时难觅i 2020-12-01 08:53

I have a UIWebView which I\'m using as an embedded browser within my app.

I\'ve noticed that links in webpages that open new windows are ignored without any call int

4条回答
  •  有刺的猬
    2020-12-01 09:16

        WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init];
        theConfiguration.preferences.javaScriptCanOpenWindowsAutomatically = YES;
    
        webView1 = [[WKWebView alloc] initWithFrame:self.webView.frame configuration:theConfiguration];
        webView1.navigationDelegate = self;
        webView1.UIDelegate = self;
        [self.view addSubview:webView1];
    
        NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
        AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
        manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
        NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
            NSString *htmlString = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
            NSLog(@"htmlString: %@", htmlString);
            [webView1 loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"your url"];
        }];
    
        [dataTask resume];
    

提交回复
热议问题