Target _blank links not opening in SFSafariViewController

1.2k Views Asked by At

I'm using the following code for opening an URL with SFSafariViewController:

import UIKit
import SafariServices

class ViewController: UIViewController, UITextViewDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        openBrowser(url: "https://www.example.com")
    }
    fileprivate func openBrowser(url: String) {
        let svc = SFSafariViewController(url: NSURL(string: url)! as URL, entersReaderIfAvailable: false)
        svc.delegate = self
        present(svc, animated: true, completion: nil)
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}

extension ViewController: SFSafariViewControllerDelegate {
    func safariViewController(_ controller: SFSafariViewController, didCompleteInitialLoad didLoadSuccessfully: Bool) {
    }
    func safariViewController(_ controller: SFSafariViewController, activityItemsFor URL: URL, title: String?) -> [UIActivity] {
        return []
    }
    func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
    }
}

This is working very well.

But if the website contains a link with target="_blank" and I'm clicking on it nothing happens.

I know that SFSafariViewController doesn't support multiple windows or tabs.

But I think there should be a possibility to ignore target="_blank" and open the link like there is no target="_blank".

Is there any way to reach this?

0

There are 0 best solutions below