Skip to content

Instantly share code, notes, and snippets.

@chamons
Created July 31, 2017 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chamons/cb0da51a4c649f9693cff01b7d7fed3f to your computer and use it in GitHub Desktop.
Save chamons/cb0da51a4c649f9693cff01b7d7fed3f to your computer and use it in GitHub Desktop.
using System;
using System.IO;
using AppKit;
using Foundation;
using WebKit;
namespace webViewTest
{
public partial class ViewController : NSViewController, IWebFrameLoadDelegate
{
public ViewController(IntPtr handle) : base(handle)
{
}
[Export ("webView:didClearWindowObject:forFrame:")]
public void ClearedWindowObject (WebView webView, WebScriptObject windowObject, WebFrame forFrame)
{
this.someWebView.WindowScriptObject.SetValueForKey (this, new NSString ("ViewController"));
InvokeOnMainThread (() =>
{
this.someLable.StringValue = "ClearedWindowObject is called";
});
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
var uri = Uri.EscapeUriString(Path.Combine(NSBundle.MainBundle.ResourcePath, "index.html"));
this.someWebView.FrameLoadDelegate = this;z
this.someLable.StringValue = "ClearedWindowObject is NOT called";
this.someWebView.MainFrame.LoadRequest(new NSUrlRequest(new NSUrl(uri)));
// Do any additional setup after loading the view.
}
public override NSObject RepresentedObject
{
get
{
return base.RepresentedObject;
}
set
{
base.RepresentedObject = value;
// Update the view, if already loaded.
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment