我正在寻找如何获得'one'和'park'字符串值(这是在UIwebview上的image_map坐标可点击点)从HTML到iPHone native obj-c。 我已经把代码放到了获取字符串值但它没有响应... plz检查和帮助
我已使用可能的答案更新了代码。如果图像映射和地图可点击表面更多,这将是复杂的。任何有关编码和解释的帮助和建议都表示赞赏。提前谢谢
更新 * 对于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;
}
答案 0 :(得分:0)
我不确定“从HTML中获取”究竟是什么意思。最可能的解决方案是使用UIWebView
javascript方法:-(NSString*)stringByEvaluatingJavaScriptFromString:
如果您想从ID为'test'的标记中获取innerHTML
:
NSString *innerHTML = [aWebview stringByEvaluatingJavaScriptFromString:@"document.getElementById('test').innerHTML"];