How to make image maps clickable using UIWebview i

2020-02-02 03:27发布

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

1条回答
霸刀☆藐视天下
2楼-- · 2020-02-02 03:58

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"];
查看更多
登录 后发表回答