Created
April 16, 2020 13:48
-
-
Save fredriccliver/558aaf5d46a63800bad0fdc1d3414ad5 to your computer and use it in GitHub Desktop.
add custom configuration into WKWebview
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// WebVC.swift | |
// test | |
// | |
// Created by 정원석 on 2020/04/16. | |
// Copyright © 2020 fred. All rights reserved. | |
// | |
import Foundation | |
import UIKit | |
import WebKit | |
class WebVC: UIViewController{ | |
// @IBOutlet weak var collinsWebView: WKWebView! | |
@IBOutlet weak var webview: WKWebView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let homeUrl:URL = URL(string: "https://www.collinsdictionary.com/")! | |
self.webview.uiDelegate = self | |
webview.allowsBackForwardNavigationGestures = true | |
webview.load(URLRequest(url: homeUrl)) | |
} | |
} | |
extension WebVC: WKUIDelegate { | |
func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? { | |
let preferences = WKPreferences() | |
preferences.javaEnabled = true | |
preferences.javaScriptCanOpenWindowsAutomatically = true | |
let configuration = WKWebViewConfiguration() | |
configuration.preferences = preferences | |
return WKWebView(frame: webView.frame, configuration: configuration) | |
} | |
} | |
extension WebVC: WKNavigationDelegate{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment