I have implemented the accepted solutions here and it does work for some websites. For eg: Go to www.tomcruise.com and click on his trailers. Each of those links have targe
I was hoping that I could solve it using the WKWebView delegate methods, but I could not figure it out.
So I went to the UIWebView era's solution of running a javascript function upon completion of web Page loading
func webView(webView: WKWebView, didFinishNavigation navigation: WKNavigation!) {
let jsCode = "var allLinks = document.getElementsByTagName('a');if (allLinks) { var i;for (i=0; i<allLinks.length; i++) {var link = allLinks[i];var target = link.getAttribute('target');if (target && target == '_blank') {link.setAttribute('target','_self');} } }"
webView.evaluateJavaScript(jsCode, completionHandler: nil)
}
This fixed the issue where tapping on the links in any google plus Posts page was resulting in an empty page being loaded
UPDATE on Nov 3rd 2015: The phenomenon explained in the question, no longer happens for me in Swift 2.0 code. So , you should be able to use the solution presented here for all your purposes