我正在寻找如何从 HTML 到 iPHone 本机 obj-c 获取“一个”和“公园”字符串值(这是 UIwebview 上的 image_map 坐标可点击点)。我已将代码放入获取字符串值但它没有响应...请检查并帮助
我已经用可能的答案更新了代码。如果图像地图和地图可点击表面更多,这将是复杂的。任何有关编码和解释的帮助和建议都将受到赞赏。提前致谢
更新: *对于 HTML 代码*
<html>
<body onload="anyFunction();">
<script language="javascript">
function anyFunction(){
window.location='value';
}
function callFromActivity(msg){
document.getElementById("circle").innerHTML = 'onclick';
}
</script>
<img src="map_new123.png" width="1500" height="731" border="0" usemap="#map" />
<a href="didTap://button1">
<map name="map">
//want ot get below onclick values one and park in to objective c .....
<area shape="circle" coords="1047,262,26" onclick="one" />
<area shape="circle" coords="1118,590,24" onclick="park" />
</a></map>
对于 obj-c
- (BOOL)webView:(UIWebView*)aWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
NSString *absoluteUrl = [[request URL] absoluteString];
if ([absoluteUrl isEqualToString:@"didTap://button1"]) {
//
UIAlertView *myAlert = [[[UIAlertView alloc] initWithTitle:@"Connectivity!" message:@" Hello" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil] autorelease];
[myAlert show];
//the below line of code should get the string but its not working
NSString* html = [myWeb stringByEvaluatingJavaScriptFromString:@"document.getElementById('circle').onclick"];
return NO;
}
return YES; }
可能的答案
//Html coding
<area shape="circle" coords="1047,262,26" onclick="one" href="didTap://button1" value="one" />
<area shape="circle" coords="1118,590,24" onclick="park" href="didTap://button2" value="park"/>
//Obj C
- (BOOL)webView:(UIWebView*)aWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
NSString *absoluteUrl = [[request URL] absoluteString];
if ([absoluteUrl isEqualToString:@"didTap://button1"]) {
UIAlertView *myAlert = [[[UIAlertView alloc] initWithTitle:@"Selected Location!" message:@"One" delegate:self cancelButtonTitle:@"GetDirection" otherButtonTitles:@"Quit",nil] autorelease];
[myAlert show];
return NO;
}
if ([absoluteUrl isEqualToString:@"didTap://button2"])
{
UIAlertView *myAlert = [[[UIAlertView alloc] initWithTitle:@"Selected Location!" message:@"Park" delegate:self cancelButtonTitle:@"GetDirection" otherButtonTitles:@"Quit",nil] autorelease];
[myAlert show];
return NO;
}
return YES;
}