Bill Daugherty Bill Daugherty - 5 months ago 13x
iOS Question

Call a javascript command in the UIWebView

I want to call a javascript command in the UIWebView page. Such as:


however I can't seem to get it to work... Here is what I have so far.
string url = "

WebView.ScalesPageToFit = true;
WebView.LoadRequest(new NSUrlRequest(new NSUrl(url)));
WebView.ScalesPageToFit = true;

But then I get a message saying

System.Exception: Could not initialize an instance of the web 'Foundation.NSUrl': the native 'initWithString:' method returned nil.


The ObjC NSURL's selector initWithString: returns nil if the value is not a correct/valid URL (and that varies a bit between iOS versions). The exception you get is Xamarin.iOS telling you that iOS itself did not like the url value you provided.

From your description I think you're looking for something like:

WebView.EvaluateJavascript ("document.getElementById(\"MainContent_btnApprove\").click();");