Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
193 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...