iPhone : load local html in uiwebview via javascri

2019-06-01 11:21发布

it's a little bit confusing I know but let's try. i have uiwebview in my iphone app and it's loaded with html local file from the bundel .. I want to put html button in this file that can load another local file using javascript ... is that possible?? is there any other approach but that ..

any help will be appreciated

2条回答
成全新的幸福
2楼-- · 2019-06-01 11:38

Loading javascript into a UIWebView from resources

In this link they have loaded local html file using javascript.

查看更多
手持菜刀,她持情操
3楼-- · 2019-06-01 11:40

You can do a custom protocol bridge between the web page and your app as the following :

In you HTML page , you may add the following a tag for example :

<a href='ToThePage2'>Click Here</a>

And in your app you'll handle this event by the following code :

webView.delegate = self;

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = request.URL;
NSString *urlString = url.absoluteString;
if([urlString isEqualToString:@"ToThePage2"])
{
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"theNextHTMLPage" ofType:@"html"]isDirectory:NO]]];
return NO;
}
return YES;
}
查看更多
登录 后发表回答