【发布时间】:2017-02-20 23:15:48
【问题描述】:
我正在尝试使用 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.Eval()方法对空白有多么挑剔。您的示例代码在右括号后显示了一个额外的空格。你有"enableBeacon(\"{0}\") ",所以也许试试"enableBeacon(\"{0}\")",注意右括号后不要有多余的空格。 -
我试图从我的函数“enableBeacon”中删除空格,但 WebView 仍然没有调用里面的 Javascript..
标签: javascript html xamarin webview xamarin.forms