Get Connection Status [JS1]
A JavaScript one-liner to find out if your device has connectivity
Description
A single line of JavaScript to find out if your device has connectivity. This is less intrusive than other methods, like getting the IP address, and can be used, for example, before trying to download something.
- No error checking
- ScPL source
navigator.onLine
documentation at MDN
Don't download the shortcut
If you just want the code, there's no need to download the shortcut. Copy this and paste it in a "URL" action:
data:text/html,<script>document.write(navigator.onLine?'online':'offline')</script>
Add a "Get File of Type" with type com.apple.webarchive
below, and its output will be the word "online" or "offline". If you prefer another output (e.g. a one instead of "online", and a zero instead of "offline") change the 'online':'offline'
near the end of the line (e.g. by 1:0
).
I use "Get File of Type" instead of "Get Contents of Webpage" to avoid that the user is misleading told that the shortcut uses Safari.
Latest Release Notes
1.0.0 - Sept. 30, 2020, 7:45 p.m.
First public version