我正在尝试使用 WebView 控件的 Eval 函数在我的 WebView 中运行 JavaScript 函数。 WebView 使用 Javascript 函数正确加载了我的 HTML,但是当我使用 WebView.Eval(javascript_function) 时,没有任何反应,并且不会调用该函数。 这是我的 CS 代码:
var _Script = string.Format("enableBeacon(\"{0}\") ", id);
_WebViewMap.Eval(_Script);
这是我的 Xaml:
<StackLayout VerticalOptions="Center" HorizontalOptions="Center">
<WebView x:Name="WebViewMap" WidthRequest="1000" HeightRequest="1000" Source="{Binding HtmlSource.HtmlUrlSource}"/>
</StackLayout>
这是我的 Javascript 函数:
function enableBeacon(id)
{
var myBeacon = document.getElementById(id);
myBeacon.style.display = "";
alert("I am an alert box!");
}
提前致谢
最佳答案
请尝试这个:
webView.Navigated += (o, s) => {
webView.Eval("alert('text')");
};
关于javascript - WebView.Eval 不在我的 HTML 中调用 javascript 函数 - Xamarin Forms,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39993753/