티스토리 뷰
import UIKit
import QRCodeReader
import AVFoundation
import WebKit
import SideMenu
class HomeViewController: UIViewController, WKNavigationDelegate, WKUIDelegate {
@IBOutlet weak var webView: WKWebView!
var popupWebView: WKWebView?
@IBAction func didTapSideBarButton(_ sender: Any) {
}
func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
popupWebView = WKWebView(frame: view.bounds, configuration: configuration)
popupWebView?.autoresizingMask = [.flexibleWidth, .flexibleHeight]
popupWebView?.navigationDelegate = self
popupWebView?.uiDelegate = self
view.addSubview(popupWebView!)
return popupWebView!
}
func webViewDidClose(_ webView: WKWebView) {
webView.removeFromSuperview()
popupWebView = nil
}
override func viewDidLoad() {
super.viewDidLoad()
webView.uiDelegate = self
webView.navigationDelegate = self
webView.configuration.preferences.javaScriptCanOpenWindowsAutomatically = true
}
[출처]
https://blog.nextzy.me/ios-handling-popup-new-window-inside-web-view-c9c91b23ac2b
'macOS, iOS' 카테고리의 다른 글
subscript 정리 (0) | 2019.12.19 |
---|---|
Swift format 프로젝트에 적용하기 (0) | 2019.12.19 |
xcode behaviors: 디버거 실행시 네비게이션 바를 hide 하고 싶다면 (0) | 2019.12.17 |
[iOS] textfield input type을 비밀번호로, 스토리보드에서 하기 (0) | 2019.12.15 |
segment control 쓰는 법 (0) | 2019.12.15 |