Cordova 插件 - stringByEvaluatingJavaScriptFromString 返回空值
Cordova Plugin - stringByEvaluatingJavaScriptFromString returning empty value
我似乎无法从我的 cordova 插件
上的 stringByEvaluatingJavaScriptFromString
函数调用接收到任何 return 值
基本上我试图在我的页面中获取活动元素,并根据 'active element'
更改我的键盘类型
我在插件初始化期间注册了 UIKeyboardWillShowNotification
,并在键盘显示监听器时触发 javascript。
这是我在插件初始化时的代码
-(void)pluginInitialize{
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(onKeyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
}
这是我在插件中显示键盘时的代码
- (void)onKeyboardWillShow:(NSNotification *)note{
NSString *script = @"document.activeElement";
if ([self.webView isKindOfClass:[UIWebView class]]) {
NSString * result = [(UIWebView*)self.webView stringByEvaluatingJavaScriptFromString:script];
NSLog(@"%@",result);
}
}
结果似乎总是 return 空字符串。我做错了什么吗?
改为document.activeElement.type
设法解决它。
stringByEvaluatingJavaScriptFromString
似乎无法 return 对象或 javascript 对象。
我似乎无法从我的 cordova 插件
上的stringByEvaluatingJavaScriptFromString
函数调用接收到任何 return 值
基本上我试图在我的页面中获取活动元素,并根据 'active element'
更改我的键盘类型我在插件初始化期间注册了 UIKeyboardWillShowNotification
,并在键盘显示监听器时触发 javascript。
这是我在插件初始化时的代码
-(void)pluginInitialize{
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(onKeyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
}
这是我在插件中显示键盘时的代码
- (void)onKeyboardWillShow:(NSNotification *)note{
NSString *script = @"document.activeElement";
if ([self.webView isKindOfClass:[UIWebView class]]) {
NSString * result = [(UIWebView*)self.webView stringByEvaluatingJavaScriptFromString:script];
NSLog(@"%@",result);
}
}
结果似乎总是 return 空字符串。我做错了什么吗?
改为document.activeElement.type
设法解决它。
stringByEvaluatingJavaScriptFromString
似乎无法 return 对象或 javascript 对象。