Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

estupefactika

macrumors member
Original poster
Feb 16, 2009
47
0
Alcobendas (Madrid)
Hi, I have a UIWebView, Ive inserted a html with a onclick to handle the action in my function.
Code:
NSString *HTMLData = @"
<div onclick='window.location=\"call?my_function\"'>Test</div>
<h1>Hello this is a test</h1>
<img src="sample.jpg" alt="" width="100" height="100" />";

[webView loadHTMLString:HTMLData baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]]];

When I click in div tag, I handle the action here:
Code:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{	
.....
		[self test];
		return YES;
}
-(void) test {
	NSLog(@"Test");	
}

The problem is nothing happends when I click. If i click for a little seconds in div tag it appears a little window entitled "Action".
But if I put:
[webView loadHTMLString:HTMLData baseURL:nil];
It works fine, I receive the call and I handle action in my method, its correct, but I need to load local files in html so I put;
[webView loadHTMLString:HTMLData baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]]];

When I do this dont works onclick and it appears me the window "Action".

Any idea? Thanks for you help
 

estupefactika

macrumors member
Original poster
Feb 16, 2009
47
0
Alcobendas (Madrid)
Really it was fine, Ive to modified my function in structure 'if' to handle action:

Code:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url=[request URL];

	NSString *scheme = [url scheme];
	NSString *tempUrl =[url query];
	if ([scheme compare:@"applewebdata"] == 0) {				
			if ([tempUrl isEqualToString:@"my_function"])
				[self test];
		return YES; 
	} else if ([scheme compare:@"file"]==0){		
			if ([tempUrl isEqualToString:@"my_function"])
				[self test];
		
		return YES;  
	} else {				
		return YES;
	}
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.