gpt4 book ai didi

c# - 在 UIWebView 中调用 javascript 命令

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:02:40 25 4
gpt4 key购买 nike

我想在 UIWebView 页面中调用一个 javascript 命令,例如:

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

但是我似乎无法让它工作。这是我目前所拥有的:

string url = "javascript:document.getElementById(\"MainContent_btnApprove\").click();";
WebView.ScalesPageToFit = true;
WebView.LoadRequest(new NSUrlRequest(new NSUrl(url)));
WebView.ScalesPageToFit = true;

然后我收到一条消息说:

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

最佳答案

ObjC NSURL 的选择器 initWithString: 返回 nil 如果该值不是正确/有效的 URL(并且有点不同iOS 版本之间)。您得到的异常是 Xamarin.iOS 告诉您 iOS 本身不喜欢您提供的 url 值。

根据您的描述,我认为您正在寻找类似的东西:

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

关于c# - 在 UIWebView 中调用 javascript 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27158830/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com