Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.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
Javascript webView中的按钮执行目标C方法_Javascript_Ios_Webview - Fatal编程技术网

Javascript webView中的按钮执行目标C方法

Javascript webView中的按钮执行目标C方法,javascript,ios,webview,Javascript,Ios,Webview,UIWebview中有一个按钮,我需要实现在点击此按钮时跳转另一个UIView的功能,换句话说,执行以下功能:[self-performsguewithidentifier:@“homePage”发送者:self] 我尝试使用shouldstartoadwithrequest函数,但它不起作用。如果你能给我看一个小的演示,你会非常感激的!谢谢 <!--index.html--> <p>Hello World!</p> <p><h1>Li

UIWebview中有一个按钮,我需要实现在点击此按钮时跳转另一个UIView的功能,换句话说,执行以下功能:[self-performsguewithidentifier:@“homePage”发送者:self]

我尝试使用shouldstartoadwithrequest函数,但它不起作用。如果你能给我看一个小的演示,你会非常感激的!谢谢

<!--index.html-->
<p>Hello World!</p>
<p><h1>Link</h1>
<a href='appintern://home'>Home</a>
</p>
<p>
<h1>Button</h1>
<form method="post" action="home">
    <button type="submit">Continue</button>
</form>
</p>
在委托方法中:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

    if (navigationType == UIWebViewNavigationTypeFormSubmitted) {
        NSString *destination = [request.URL lastPathComponent];
        if ([destination isEqualToString:@"home"]) {
            NSLog(@"go to home");
            //[self performSegueWithIdentifier:@"homePage" sender:self];
            return NO;
        }
    }
    else if (navigationType == UIWebViewNavigationTypeLinkClicked) {
        // todo
    }

    return YES;
}

希望有帮助。

您需要使用URL方案从html网页与Obj C进行通信:


让您的提交按钮打开URL方案,您将驱动您想要的结果。提示:URL方案实际上是类似API的调用。您需要确保它们包含足够的Idenfying信息,以便可以智能地添加更多方案。

Nice!我忘了设置webview的代理。问题已经解决了。谢谢你的帮助。谢谢你的回复。这也很有帮助。
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

    if (navigationType == UIWebViewNavigationTypeFormSubmitted) {
        NSString *destination = [request.URL lastPathComponent];
        if ([destination isEqualToString:@"home"]) {
            NSLog(@"go to home");
            //[self performSegueWithIdentifier:@"homePage" sender:self];
            return NO;
        }
    }
    else if (navigationType == UIWebViewNavigationTypeLinkClicked) {
        // todo
    }

    return YES;
}