我在这些论坛的第一篇文章 :)
这适用于移动浏览器(在这种情况下为 android)。在我知道要使用哪个功能之前,我需要检查计算机是否打开。
有没有办法可以 ping 它以确定它的网络存在并运行相应的功能?现在,我只有要测试的消息。(navigator.notification.alert 是用于在移动设备上显示消息的 Cordova 方法)
我已经编写了这段代码,有什么办法可以让它工作,我做了一些谷歌搜索无济于事。
请注意,这是在本地网络上工作的。
function isOn() {
$.ajax({
url : 'http://192.168.x.xxx' , //x.xxx being the client ip
success : function () {
navigator.notification.alert(
'The computer is on.', //Message body
alertDismissed, //Callback
'The Computer is On', //Title
'Yes' //Button Label
);
},
error : function () {
navigator.notification.alert(
'The computer is off.', //Message body
alertDismissed, //Callback
'The Computer is Off', //Title
'Yes' //Button Label
);
}
});
};
<a onclick="isOn();">Test</a>