Welcome to my first post on this forum!
I am working on a project for a mobile browser (specifically Android). I am trying to determine if a computer is turned on before deciding which function to execute.
Is there a way to ping the computer to check its network presence and then run the appropriate function? Right now, I am just displaying test messages. Please note that I am using navigator.notification.alert method in Cordova to show messages on the mobile device.
I have come up with some code, but it doesn't seem to be working. I tried searching online without much success.
Keep in mind that this needs to work within a local network.
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>