我使用WKWebView在我的项目中加载网页。我想在网页加载后隐藏div标签。因此,我使用Objective-C evaluateJavaScript:completionHandler:
方法来评估我的JavaScript字符串。比起CompleteHandler,我得到了一个错误。
打印错误说明:
错误域= WKErrorDomain代码= 4“发生JavaScript异常” UserInfo = {WKJavaScriptExceptionLineNumber = 1,WKJavaScriptExceptionMessage = TypeError:未定义不是对象(评估'document.getElementsByClassName('wapim-conversation-banner')[0] .style') ,WKJavaScriptExceptionColumnNumber = 64,WKJavaScriptExceptionSourceURL = https://h5.youzan.com/v2/im?c=wsc&v=2&kdt_id=42724847#/index,NSLocalizedDescription = happen JavaScript exception}
有人建议处理此问题吗?谢谢。
// When using in picture border rectangle outside class, i can get DOM node, but when using border rectangle inside class get same error detail infomations. Such as using `wapim-app-content` or `wapim-container` or `platform-unknown im-for-wsc` class it work well, but using other class name get same error
NSMutableString *jsonStr = [NSMutableString string];
NSString *jsStr1 = @"document.getElementsByClassName('wapim-conversation-banner')[0].style.display='none'";
[jsonStr appendString:jsStr1];
[self.contentWebView evaluateJavaScript:jsonStr completionHandler:^(id _Nullable value, NSError * _Nullable error) {
}];