0

一部のJavaScriptも実行されているUIWebViewがあります。最初のボタンをクリックすると、JavaScript コードが適切に実行され、完全に機能しますが、他のボタンをクリックしてから古いビューに戻ると、JavaScript は機能しませんでした。以下は私のコードです。

- (void)webViewDidStartLoad:(UIWebView *)webView { 
    NSMutableString *javascriptFunctions = [NSMutableString stringWithString:@"var t3 = new function() { this.setTitle = function(text) { window.location.href = 'about:title:' + encodeURIComponent(text); }; "];
    [javascriptFunctions appendString:@"this.setAppointment = function(beginTime, endTime, title, description, isUTC) { window.location.href = 't3://web-command/calendar?beginTime=' + encodeURIComponent(beginTime) + '&endTime=' + encodeURIComponent(endTime) + '&title=' + encodeURIComponent(title) + '&description=' + encodeURIComponent(description) + '&isUTC=' + encodeURIComponent(isUTC); }; "];
    [javascriptFunctions appendString:@"this.setBackButtonVisibility = function(isVisible) { window.location.href = 'about:back:' + encodeURIComponent(isVisible); }; "];
    [javascriptFunctions appendString:@"this.getBack = function() { window.history.back(); }; "];
    [javascriptFunctions appendString:@"this.close = function() { window.location.href = 'about:close'; }; }"];

    [self.webView stringByEvaluatingJavaScriptFromString:javascriptFunctions];
}


- (BOOL)webView:(UIWebView *)currentWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    if ([[request.URL.scheme lowercaseString] isEqualToString:@"tel"]) {
        return YES;
    }

    NSString* url = [request.URL.absoluteString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

    if (url == nil) {
        [self backToMainScreen];
    return NO;
    }
}
4

1 に答える 1