如何在 iphone 中使用 UIWebview 使图像地图可点击?

2023-10-22移动开发问题
0

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

问题描述

我正在寻找如何从 HTML 到 iPHone 原生 obj-c 的 onclick 获取 'one' 和 'park' 字符串值(这是 UIwebview 上的 image_map 坐标可点击点).我已将代码用于获取字符串值,但它没有响应...请检查并帮助

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

更新:*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;
}

推荐答案

我不确定您所说的从 HTML 获取"到底是什么意思.最可能的解决方案是使用 UIWebView javascript 方法:-(NSString*)stringByEvaluatingJavaScriptFromString:

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:

如果你想从id为'test'的标签中获取innerHTML:

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

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

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

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

Cocos2d - 如何检查不同层中对象之间的交集
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)...
2024-08-12 移动开发问题
8

突出显示朗读文本(在 iPhone 的故事书类型应用程序中)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))...
2024-08-12 移动开发问题
9

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

正确的 cocos2d 场景重启?
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)...
2024-08-12 移动开发问题
7

[ios.cocos2d+box2d]如何禁用自动旋转?
[ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)...
2024-08-12 移动开发问题
7