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];
}
#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];
}
相关文章推荐
- iOS ---oc和js交互
- ios项目中引用其他项目复习
- iOS 提高tableView 性能的优化
- 芒果iOS开发之Project/Users/用户名/.../xxx.xcodeproj cannot be open because the project file cannot be parsed
- iOS 删除NSString中特定字符
- IOS 基础动画Core Animation
- 芒果iOS开发之 CONFLICT (content): AutoMatic merge failed;fix conflicts and then commit the result.
- 芒果iOS开发之Merge branch 'master' of XXX Please enter a commit message to explain why this merge
- iOS开发之数据存储(偏好设置)
- IOS九宫格设计源码(外加添加删除功能)
- iOS开发之数据的写入与读取(plist存储)
- iOS 代码规范
- iOS之有关于git的命令行
- IOS常用延时操作
- Habber - IOS XMPP 客户端 教程 (续)对方输入状态显示
- 芒果iOS开发之git新手常用操作
- iOS 日期格式化, NSDateFormatter,把服务器返回的时间,格式化为时间戳
- 编写高质量iOS 与OSX 代码的52个有效方法之块与大中枢派发
- IOS cocoapods 第三方库的管理工具
- iOS 上传头像处理