pass values between C# and JavaScript
Posted: Sun Feb 07, 2016 8:28 am
I have successfully injected some javascript using the JSIL.Verbatim mechanism (see below) but what I can't quite figure out is how to pass values back and forth between the two.
Can anyone tell me how to do this? Are there any additional samples of examples that maybe I am overlooking?
Can anyone tell me how to do this? Are there any additional samples of examples that maybe I am overlooking?
Code: Select all
private void gpsButton_Click(object sender, RoutedEventArgs e)
{
if (CSharpXamlForHtml5.Environment.IsRunningInJavaScript)
{
//how do I get value or lat and lon from
JSIL.Verbatim.Expression(@"
function getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition);
}
}
function showPosition(position)
{
alert(""Latitude: "" + position.coords.latitude + "" Longitude: "" + position.coords.longitude);
}
getLocation();");
}
else
{
gpsValue.Text = "Cannot run script in simulator.";
}
}