0
我設置了以下函數來通知我的瀏覽器當前連接類型。由於某種原因,這返回null。難道我做錯了什麼?需要注意的是,我不相信在ScriptNotify中獲取值是問題所在,我對其他可以正常工作的函數使用相同的方法。看來navigator.connection爲null。如何在JavaScript中確定連接類型
的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);
}
'navigator.connection'不可用在IE 10的Windows Phone。我也發佈了我的其他更新的解決方案http://stackoverflow.com/questions/22777362/calculating-speed-using-javascript-returns-nan但我無法確定錯誤可能是什麼。也許你可以看看? – Matthew