Route clicked links in the web view to the default web browser

This commit is contained in:
Grant Limberg 2016-07-26 18:21:39 -07:00
parent 693ac4e86c
commit 62befe006d

View File

@ -9,13 +9,15 @@
import Cocoa
import WebKit
class AboutViewController: NSViewController {
class AboutViewController: NSViewController, WebPolicyDelegate {
@IBOutlet var webView: WebView!
override func viewDidLoad() {
super.viewDidLoad()
webView.policyDelegate = self
// Do view setup here.
let bundle = NSBundle.mainBundle()
let path = bundle.URLForResource("about", withExtension: "html")
@ -25,4 +27,18 @@ class AboutViewController: NSViewController {
}
}
func webView(webView: WebView!,
decidePolicyForNavigationAction actionInformation: [NSObject : AnyObject]!,
request: NSURLRequest!,
frame: WebFrame!,
decisionListener listener: WebPolicyDecisionListener!) {
if (request.URL?.host) != nil {
NSWorkspace.sharedWorkspace().openURL(request.URL!)
}
else {
listener.use()
}
}
}