【发布时间】:2014-04-01 04:40:43
【问题描述】:
我设置了以下功能来通知我的浏览器当前的连接类型。出于某种原因,这将返回 null。难道我做错了什么?需要注意的是,我不认为在 ScriptNotify 中获取值是问题所在,我对其他可以正常工作的函数使用相同的方法。 navigator.connection 似乎为空。
JavaScript
function getConnectionType() {
var connectionType = navigator.connection;
window.external.notify("Connection type: " + connectionType.toString());
}
C#
在按钮单击事件中,我使用 InvokeScript 调用函数
object connectionType = Browser.InvokeScript("getConnectionType");
然后
private void Browser_ScriptNotify(object sender, NotifyEventArgs e)
{
string value = null;
value = e.Value.ToString();
ResultTextBlock.Text = value;
}
编辑 javascript 更新
function getConnectionType() {
//var connectionType = navigator.connection;
var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
var connectionType = connection.type
window.external.notify("COT" + connectionType);
}
【问题讨论】:
标签: c# javascript html