有没有办法使用Phonegap ping网站?我正在尝试对Phonegap进行能耗测试。我已经完成了连接测试,但想要ping一个站点
function check_network() {
var networkState = navigator.network.connection.type;
var states = {};
states[Connection.UNKNOWN] = 'Unknown connection';
states[Connection.ETHERNET] = 'Ethernet connection';
states[Connection.WIFI] = 'WiFi connection';
states[Connection.CELL_2G] = 'Cell 2G connection';
states[Connection.CELL_3G] = 'Cell 3G connection';
states[Connection.CELL_4G] = 'Cell 4G connection';
states[Connection.NONE] = 'No network connection';
confirm('Connection type:\n ' + states[networkState]);
}
答案 0 :(得分:0)
如果您能够在服务器上运行类似node.js + socket.io的内容,那么您可以使用它来模仿ping:https://github.com/guille/latency-io
您还可以执行XMLHttpRequest
(或jQuery.get())并计算请求和响应之间的时差。但这不会很准确。即:How to ping in JavaScript or jQuery?
你无法真正做到真正的ping
,Phonegap API不允许你开箱即用。您可以构建一个插件来执行此类操作,但之后您必须为每个平台编写该本机插件(即http://www.adobe.com/devnet/html5/articles/extending-phonegap-with-native-plugins-for-android.html)。