1、js調用ochtml
#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. NSURL *url=[[NSBundle mainBundle]URLForResource:@"test" withExtension:@"html"]; NSURLRequest *request=[[NSURLRequest alloc]initWithURL:url]; self.webview.delegate=self; [self.webview loadRequest:request]; } -(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { NSLog(@"%@",request.URL.absoluteString); NSString *str=request.URL.absoluteString; NSRange range=[str rangeOfString:@"dswq:///"]; NSUInteger location=range.location; if (location != NSNotFound) { NSString *method=[str substringFromIndex:location+range.length]; SEL sel=NSSelectorFromString(method); [self performSelector:sel]; } return YES; } -(void)openCamera{ UIImagePickerController *pickerVC=[[UIImagePickerController alloc]init]; pickerVC.sourceType=UIImagePickerControllerSourceTypePhotoLibrary; [self presentViewController:pickerVC animated:YES completion:nil]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
2、oc調用jsios
- (void)viewDidLoad { [superviewDidLoad]; self.webView.scrollView.hidden =YES; self.webView.backgroundColor = [UIColorgrayColor]; // 加載一個網頁 NSURL *url = [NSURLURLWithString:@"http://www.xianhua.cn/m/"]; NSURLRequest *request = [NSURLRequestrequestWithURL:url]; [self.webViewloadRequest:request]; } #pragma mark - <UIWebViewDelegate> -(void)webViewDidFinishLoad:(UIWebView *)webView{ // 刪除底部的廣告 NSString *str = @" document.getElementsByClassName('detail_btns2')[0].remove();"; [webViewstringByEvaluatingJavaScriptFromString:str]; // 修改標題 NSString *str2 = @"document.getElementsByTagName('h1')[0].innerText = '--鮮花網--';"; [webViewstringByEvaluatingJavaScriptFromString:str2]; // 修改底部的標題 NSString *str3 = @"document.getElementById('xiazaiapp').getElementsByTagName('a')[0].innerText = '--下載鮮花網APP--';"; [webViewstringByEvaluatingJavaScriptFromString:str3]; }轉載:http://blog.csdn.net/wzios/article/details/61202082