我知道这有点令人困惑,但让我们试试吧。 我的 iphone 应用程序中有 uiwebview,它加载了 bundel 中的 html 本地文件。我想在此文件中放置 html 按钮,它可以使用 javascript 加载另一个本地文件 ... 那可能吗??除了..还有其他方法吗?
任何帮助将不胜感激
最佳答案
您可以按照以下方式在网页和您的应用程序之间建立自定义协议(protocol)桥接:
在您的 HTML 页面中,您可以添加以下 a
标记,例如:
<a href='ToThePage2'>Click Here</a>
在您的应用中,您将通过以下代码处理此事件:
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;
}
关于javascript - iPhone : load local html in uiwebview via javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9640324/