문제

Is the areanything special you need in html or Callbacks in a UIWebView to handle anchor tags with an href, or is there something special about an anchor tag with a mailto link in the href?

도움이 되었습니까?

해결책

In your UIWebView's delegate, do:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    if ([[[request URL] scheme] isEqual:@"mailto"]) {
        [[UIApplication sharedApplication] openURL:[request URL]];
        return NO;
    }
    return YES;
}

다른 팁

JavaScriptFilteredIntOfooterHeadErresponse를 무시할 필요가 없습니다. 다음 생성자를 사용하여 org.apache.wicket.resource.filtering.headerresponseContainerFilteringHeadErResponseContainerFilteringHeadErresponse 을 사용하십시오.

HeaderResponseContainerFilteringHeaderResponse(IHeaderResponse response, 
        String headerFilterName, IHeaderResponseFilter[] filters)
.

예를 들어, 쓰는 경우 :

IHeaderResponseFilter[] filters = new IHeaderResponseFilter[] { 
        new CssAcceptingHeaderResponseFilter(HEADER_FILTER_NAME),
        new JavascriptAcceptingHeaderResponseFilter(FOOTER_FILTER_NAME) };

return new HeaderResponseContainerFilteringHeaderResponse(response, 
        HEADER_FILTER_NAME, filters);
.

코드에서 사용하는 것과 동일한 JavaScriptFilterEdIntoFooterHeadErresponse입니다.

여기에 CSSAcceptingHeadErresponseFilter 대신에 사용할 수있는 익명 필터 클래스의 예제는 작업을 수행합니다. 파일 "script-for-the-header.js"는 헤더에 갖고 싶은 스크립트입니다.

new CssAcceptingHeaderResponseFilter(HEADER_FILTER_NAME) {

    @Override
    public boolean acceptReference(ResourceReference ref) {
        if (!Strings.isEmpty(ref.getName()) && ref.getName().equals("script-for-the-header.js")) {
            return true;
        } else {
            return super.acceptReference(ref);
        }
    }
}
.

코드를보다 잘 구성하려면 headerresponseContainerFilteringHeadErResponse를 무시하는 것이 좋습니다 (아직 추측하지 않은 경우 JavaScriptFilteredIntoFooterHeadErresponse의 부모도). 자세한 내용은 자세한 내용입니다.

I wanted to note that this is probably not the best solution.

UIWebView does have a property called dataDetectorTypes - setting this to all or address should solve your problem without overriding the Method mentioned above:

myWebView.dataDetectorTypes = UIDataDetectorTypeAll; //or UIDataDetectorTypeAddress etc..

But be aware that this might not work on the simulator - I tried it with the iPad 6.0 Simulator where it's not working although on an iPad Device it's working like a charm!

Working example for Swift 4: 3 cases are treated, expand as needed.

  1. mailto-link is working
  2. some URL is clicked that you want to open in Webview itself
  3. open all other URLs in mobile safari

    func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
    
    if let url = navigationAction.request.url {
        if (url.scheme == "mailto") {
            // mailto: link is clicked
            UIApplication.shared.open(url)
            decisionHandler(.cancel)
            return
        }
        if (url.absoluteString.contains("www.example.com/webviewURL")) {
            // Load this stuff in WebView
            decisionHandler(.allow)
            return
        } else {
            // open any other URL in mobile Safari
            UIApplication.shared.open(url)
            decisionHandler(.cancel)
            return
        }
    }
    
    decisionHandler(.cancel)
    return
    }
    
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top