Last active
January 23, 2016 22:53
-
-
Save Corstiaan84/56a0346d67c9077b45aa to your computer and use it in GitHub Desktop.
This file contains 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
public partial class DomLoadedExampleController : UIViewController | |
{ | |
private UIWebView _webView; | |
private event EventHandler DomReady; | |
public override void ViewDidLoad () | |
{ | |
base.ViewDidLoad (); | |
//initialze UIWebView instance | |
_webView = new UIWebView (new Rectangle (0, 0, (int)UIScreen.MainScreen.Bounds.Width, (int)UIScreen.MainScreen.Bounds.Height)); | |
//wire up DomReady event handler | |
DomReady += (object sender, EventArgs e) => { | |
//handle the event | |
new UIAlertView ("DOM Loaded!", "The DOM has loaded!", null, "OK", null).Show (); | |
}; | |
//this is called when a link/a element is clicked inside the webview and the location.href is set to a new value | |
//we can catch it to determine if the request.Url contains our "domReady" string | |
_webView.ShouldStartLoad = (UIWebView webView, NSUrlRequest request, UIWebViewNavigationType navType) => { | |
if(request.Url.AbsoluteString.Contains("domReady")) { | |
//url contains "domReady". This is our cue :-) | |
if(DomReady != null) { | |
//fire event | |
DomReady(this, EventArgs.Empty); | |
//do not allow UIWebView to follow this url | |
return false; | |
} | |
} | |
return true; | |
}; | |
_webView.LoadHtmlString ("the html shown above", NSBundle.MainBundle.BundleUrl); | |
Add (_webView); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment