JavaScript ES6, 7171 43 bytes
fetch``.then(a=>alert(1)).catch(a=>alert``) Alerts 1 if online, alerts an empty string if offline. Thanks to Patrick Roberts for helping me shave off some bytes
Old version
_=>fetch('http://enable-cors.org').then(a=>alert(a)).catch(a=>alert(0)) Alerts [object Reponse] if online, alerts 0 if offline
f=_=>fetch('http://enable-cors.org').then(a=>alert(a)).catch(a=>alert(0)) f();