Created
August 1, 2013 01:58
-
-
Save roshanca/6127845 to your computer and use it in GitHub Desktop.
use to test ping.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ping(ip) { | |
var img = new Image(); | |
var start = new Date().getTime(); | |
img.src = 'http://' + ip + '?t=' + start; | |
var flag = false; | |
img.onload = function () { | |
flag = true; | |
console.log('ok'); | |
} | |
img.onerror = function () { | |
flag = true; | |
console.log('ok'); | |
} | |
var timer = setTimeout(function () { | |
if (!flag) { | |
flag = false; | |
console.log('failed'); | |
} | |
}, 1500); | |
} | |
ping('192.168.1.1'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment