Anonymous Anonymous - 3 months ago
134 0

No description

Swift

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() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        
        var url = NSURL(string: "http://huttle.co")
        
        var request = NSURLRequest(URL: url!)
        
        webView.loadRequest(request)

        
        /*
        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
            self.view.addSubview(popup)
            return popup
        }
        return nil;
    }
    func webViewDidClose(webView: WKWebView) {
        // Popup window is closed, we remove it
        webView.removeFromSuperview()
    }

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


}