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 文字列を作成する必要があります。 .