我写了这段代码:
if navigationType == UIWebViewNavigationType.LinkClicked {
UIApplication.sharedApplication().openURL(request.URL!)
return false
}
它适用于所有普通网址。但是当我用下一个代码点击图像/ gif时:
<a href="https://cdn-images-1.medium.com/max/800/1*IR7oti7mEsYunzp_HhcNig.gif"
target="_blank" class="c"
style="background-image: url('//cdn.iframe.ly/pj?url=https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1*IR7oti7mEsYunzp_HhcNig.gif&width=1280&
key=9b0e65e32a5412cf736c430972d914c33f46250b&cache=temp');">
1*IR7oti7mEsYunzp_HhcNig.gif </a>
它在我的应用程序中打开了这个gif / URL,在UIWebView中。
我怎么强迫它也会在Safari中打开那个gif / URL?
答案 0 :(得分:0)
必须在代码中的其他位置破坏某些内容。 工作正常如下:
import UIKit
class ViewController: UIViewController, UIWebViewDelegate {
@IBOutlet var webView : UIWebView?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.webView?.loadHTMLString("<a href='https://cdn-images-1.medium.com/max/800/1*IR7oti7mEsYunzp_HhcNig.gif' target='_blank' class='c' style='background-image: url('//cdn.iframe.ly/pj?url=https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1*IR7oti7mEsYunzp_HhcNig.gif&width=1280& key=9b0e65e32a5412cf736c430972d914c33f46250b&cache=temp');'> 1*IR7oti7mEsYunzp_HhcNig.gif </a>", baseURL: NSURL(string: "testurl.com"))
}
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
if navigationType == UIWebViewNavigationType.LinkClicked {
UIApplication.sharedApplication().openURL(request.URL!)
return false
}
return true
}
}