在您的 nextPage 和 prevPage javascript 方法中,创建一个您可以在 Web 视图委托中解析的自定义 url:
function nextPage()
{
window.location.href = "file://yourappname?nextPage";
}
function prevPage()
{
window.location.href = "file://yourappname?prevPage";
}
然后在您的 Web 视图委托中,实现 shouldStartLoadWithRequest:
-(BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType
{
NSString *urlString = request.URL.absoluteString;
if (urlString hasSuffix:@"prevPage"])
{
NSURL *url = [NSURL urlWithString:@"Page1.html"];
NSURLRequest *urlRequest = [NSUrlRequest requestWithURL:url];
[webView loadRequest:urlRequest];
}
else if ([queryString hasSuffix:@"nextPage"])
{
NSURL *url = [NSURL urlWithString:@"Page3.html"];
NSURLRequest *urlRequest = [NSUrlRequest requestWithURL:url];
[webView loadRequest:urlRequest];
}
return YES;
}
当然这只是一个简单的例子——在实际代码中,您需要用代码替换 @"Page1.html" 和 @"Page3.html" 以跟踪当前页面并构建您的 url 字符串以相应地向前或向后翻页.