我使用javascript / jquery来隐藏/显示div
div内容是电话号码/地址......
看来Adress检测对可见Div有效。它没有隐藏的div。而且我没有设法迫使ios再次解析de WebView。
有人有实验同样的麻烦拍摄吗?任何的想法? thx提前
以下是一些示例代码:
NSString * defaultString=[NSString stringWithFormat:
@"<div onclick='hiddeDiv(this)' id=title%i>"
"<h2>"
"H2Title"
"</h2>"
"</div>"
"<hr>"
"<div id=hidden%i style='display:none;'>"
"ADRESSE OR PHONE"
"</div>"
"",1,1];
[webView loadHTMLString:defaultString baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]]];
[webView setDataDetectorTypes:UIDataDetectorTypeAll];
的script.js
function hiddeDiv(element) {
var newId=element.id.replace('title','');
var elementHidden = document.getElementById('hidden'+newId);
if (elementHidden.style.display == 'none'){
$( '#hidden'+newId ).show(400,function(){$('html, body').animate({ scrollTop: $('#title'+newId).offset().top - 20}, 600);});
}
else { $( "#hidden"+newId ).hide(400);}
window.location.href = "detectAdress://hiddeDiv";//-->Handle event in xcode
};
处理xcode中的事件:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:{
if (navigationType == UIWebViewNavigationTypeOther){
scheme = [[request URL] scheme];
if ([scheme isEqualToString: @"detectadress"]) {
dispatch_async(dispatch_get_main_queue(), ^{
[webView setDataDetectorTypes:UIDataDetectorTypeAll];//--> I want to force new detection after div is show but it doesn't work
});
return NO;
}
}
return YES;
}