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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…