iPhone : load local html in uiwebview via javascript

半城伤御伤魂 提交于 2019-12-08 04:26:15

问题


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


回答1:


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



回答2:


Loading javascript into a UIWebView from resources

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



来源:https://stackoverflow.com/questions/9640324/iphone-load-local-html-in-uiwebview-via-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!