Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
UIWebView在iOS中执行JavaScript时显示错误_Ios_Sdk_Uiwebview - Fatal编程技术网

UIWebView在iOS中执行JavaScript时显示错误

UIWebView在iOS中执行JavaScript时显示错误,ios,sdk,uiwebview,Ios,Sdk,Uiwebview,我有一个UIWebView,其中还执行了一些javascript。当我们点击第一个按钮时,它会正确地执行javascript代码并完美地工作,但是当我们点击任何其他按钮,然后导航回旧视图时,javascript不工作。下面是我的代码 - (void)webViewDidStartLoad:(UIWebView *)webView { NSMutableString *javascriptFunctions = [NSMutableString stringWithString:@"va

我有一个UIWebView,其中还执行了一些javascript。当我们点击第一个按钮时,它会正确地执行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;
    }
}

在网页完全加载到UIWebView上之前,Javascript函数不会调用。在委托方法webViewDidFinishLoad中调用了所有javascript函数

 - (void)webViewDidFinishLoad:(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];



   }