javascript - WebView.Eval 不在我的 HTML 中调用 javascript 函数 - Xamarin Forms

标签 javascript html xamarin webview xamarin.forms

我正在尝试使用 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/

相关文章:

c# - 使按钮打开超链接

javascript - angularjs 中的 Math.ceil 返回错误值

javascript - 新对象()未定义?

html - 为什么表格宽度和文本大小相对于彼此的比例不同?

jquery - 使用 jQuery 定位除 DIV 中的链接之外的所有链接

c# - 如何创建或生成 .mlpd 文件以检查 xamarin 分析器中的应用程序性能

加载需要其他 javascript 文件的 php 文件时未加载 Javascript

javascript - 如何重播通过添加带有过渡的类触发的动画?

javascript - 为什么 offsetParent 忽略我的文章标签?

android - 如何从 Visual Studio 2015 运行 Xamarin Android Player?