如何在iPhone中使用UIWebview使图像地图可点击? [英] How to make image maps clickable using UIWebview in iphone?

查看:85
本文介绍了如何在iPhone中使用UIWebview使图像地图可点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找如何从HTML到iPHone native obj-c获取'one'和'park'字符串值(这是image_map在UIwebview的坐标点上可点击的位置)。
我已经把代码获得字符串值,但它没有响应... plz检查和帮助

我用可能的答案更新了代码即可。如果图像地图和地图可点击表面更多,这将变得复杂。编码和解释任何帮助和建议,这是值得赞赏的。在此先感谢

已更新:
* 对于HTML代码 *

 < html> 
< body onload =anyFunction();>
< script language =javascript>

函数anyFunction(){
window.location ='value';
}

function callFromActivity(msg){
document.getElementById(circle)。innerHTML ='onclick';
}
< / script>

< img src =map_new123.pngwidth =1500height =731border =0usemap =#map/>
< a href =didTap:// button1>
< map name =map>
//想获得低于onclick的值并停留在目标c .....
< area shape =circlecoords =1118,590,24onclick =park/>
< / a>< / map>

对于Obj-c

   - (BOOL)web视图:(的UIWebView *)aWebView shouldStartLoadWithRequest:(的NSURLRequest *)请求navigationType:(UIWebViewNavigationType)navigationType 
{
的NSString * absoluteUrl = [[request URL] absoluteString];
如果([absoluteUrl isEqualToString:@ didTap:// Button1的]){
//
UIAlertView中* myAlert = [[[UIAlertView中页头] initWithTitle:@ 连通性! message:@Hellodelegate:nil cancelButtonTitle:@OkotherButtonTitles:nil] autorelease];
[myAlert show];

//的代码下面的行应该得到的字符串,但它不工作

的NSString * HTML = [MYWEB stringByEvaluatingJavaScriptFromString:@的document.getElementById( '圆圈')。的onclick];

return NO;
}
返回YES; }

可能的答案

  // Html编码
< area shape =circlecoords =1118,590,24onclick =parkhref =didTap:// button2value =park/>


//的OBJ C
$ B $期B - (BOOL)web视图:(的UIWebView *)aWebView shouldStartLoadWithRequest:(的NSURLRequest *)请求navigationType:(UIWebViewNavigationType)navigationType
{
NSString * absoluteUrl = [[request URL] absoluteString];
如果([absoluteUrl isEqualToString:@ didTap:// Button1的]){
UIAlertView中* myAlert = [[[UIAlertView中页头] initWithTitle: 选址 @ message:@Onedelegate:self cancelButtonTitle:@GetDirectionotherButtonTitles:@Quit,nil] autorelease];
[myAlert show];

return NO;
}
如果([absoluteUrl isEqualToString:@ didTap:// BUTTON2])
{
UIAlertView中* myAlert = [[[UIAlertView中的alloc] initWithTitle:@选址!消息:@Park委托:self cancelButtonTitle:@GetDirectionotherButtonTitles:@Quit,nil] autorelease];
[myAlert show];
return NO;
}
返回YES;
}


解决方案

我不确定究竟是什么你的意思是从HTML获取。最可能的解决方案是使用 UIWebView javascript方法: - (NSString *)stringByEvaluatingJavaScriptFromString:



如果您想从ID为'test'的标签获取 innerHTML

  NSString * innerHTML = [aWebview stringByEvaluatingJavaScriptFromString:@document.getElementById('test')。innerHTML]; 


I am looking how to get 'one' and 'park' string value (which is image_map coordinates clickable spot on UIwebview's) onclick from HTML to iPHone native obj-c. I have put the code to get string value but it is not responding...plz check and help

I have updated code with possible answer. Which will be complicated if the image maps and map clickable surfaces are more. Any help and suggestion with coding and explaination on this are appreciated. thanks in advance

Updated: *For HTML code*

<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>

For 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; }

Possible answer

//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;
}

解决方案

I am not sure what exactly you mean by "fetch from HTML". The most likely solution will be to use UIWebView javascript method: -(NSString*)stringByEvaluatingJavaScriptFromString:

If you want to get the innerHTML from the tag with id 'test':

NSString *innerHTML = [aWebview stringByEvaluatingJavaScriptFromString:@"document.getElementById('test').innerHTML"];

这篇关于如何在iPhone中使用UIWebview使图像地图可点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆