Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
195 views
in Technique[技术] by (71.8m points)

html - How to make image maps clickable using UIWebview in iphone?

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;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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"];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...