2

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

javascript:document.getElementById(\"MainContent_btnApprove\").click();

however I can't seem to get it to work. Here is what I have so far:

string url = "javascript:document.getElementById(\"MainContent_btnApprove\").click();";
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.

1 Answer 1

2

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();");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.