Anonymous Anonymous - 1 year ago
495 0

No description


Share with Geoff

//  ViewController.swift
//  Webviews
//  Created by Christopher Tung on 1/23/16.
//  Copyright © 2016 A & C Romance Factory. All rights reserved.

import UIKit
import WebKit

class ViewController: UIViewController, WKUIDelegate {

    @IBOutlet var webView: WKWebView!
    override func viewDidLoad() {
        // Do any additional setup after loading the view, typically from a nib.
        var url = NSURL(string: "")
        var request = NSURLRequest(URL: url!)

        var html = "<html><body><h1>My Page </h1><p>This is my web page. </p></body></html>"
        webView.loadHTMLString(html, baseURL: nil)
    func webView(webView: WKWebView, createWebViewWithConfiguration configuration: WKWebViewConfiguration, forNavigationAction navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
        // A nil targetFrame means a new window (from Apple's doc)
        if (navigationAction.targetFrame == nil) {
            // Let's create a new webview on the fly with the provided configuration,
            // set us as the UI delegate and return the handle to the parent webview
            let popup = WKWebView(frame: self.view.frame, configuration: configuration)
            popup.UIDelegate = self
            return popup
        return nil;
    func webViewDidClose(webView: WKWebView) {
        // Popup window is closed, we remove it

    override func didReceiveMemoryWarning() {
        // Dispose of any resources that can be recreated.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download