您的位置:首页 > 移动开发 > IOS开发

iOS ---oc和js交互2

2015-12-27 18:04 447 查看
导入

#import <JavaScriptCore/JavaScriptCore.h>

@interface
WebViewController ()<UIWebViewDelegate>

@property(nonatomic,strong)
UIWebView *web2;

#pragma mark - 加载网页

-(void)Reloadweb{

// _web2 =[[UIWebView alloc]initWithFrame:[UIScreen mainScreen].bounds];

_web2 = [[UIWebView
alloc]initWithFrame:CGRectMake(0,
0, self.view.width,
self.view.height)];

NSString *url =
@"网址";

[_web2
loadRequest:[NSURLRequest
requestWithURL:[NSURL
URLWithString:url]]];

_web2.delegate=self;

[self.view
addSubview:_web2];

}

//网页加载完成的事件
- (void)webViewDidFinishLoad:(UIWebView *)webView {

//首先创建JSContext
对象(此处通过当前webView的键获取到jscontext)

JSContext *context=[webView
valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];

//同样我们也用刚才的方式模拟一下js调用方法(调用js的方法)

NSString *jsStr1=@"removeButton()";

[context
evaluateScript:jsStr1];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: