I have some code that if I’m at home; it will display at popup saying that if you are at home. If you are not at home it will display a popup saying you are not at home. As the script is located on a server to give an IP address, how can I get it to say if you are not connected to the internet, as it will fail to load so I would have though that ip!=”” would work but doesn’t what have I done wrong?
Thanks
<script type="application/javascript">
function getip(json)
{
ip=json.ip
if(ip!="")
{
if(ip=="123.123.123.123")
{
alert("You are at home");
}
else
{
alert("you are not at home");
}
}
else
{
alert("You are not connected to the internet");
}
}
</script>
<script type="application/javascript" src="http://jsonip.appspot.com/?callback=getip">
</script>
The way JSONP works is to call that method with the response, your server response from
http://jsonip.appspot.com/?callback=getiplooks something like this:But when you’re not connected that script include just errors, and the method isn’t ever called, that’s the issue. Your
ifcheck, and the entiregetip()method, isn’t ever hit. You could do a very simple timeout, like this: