Last active
August 29, 2015 14:19
-
-
Save mhulse/ce208d2c64f1ce160a6a to your computer and use it in GitHub Desktop.
[not-online] Simplistic JavaScript code to detect if network is online/offline; "online" is assumed to be the default mode.
This file contains hidden or 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
/*! not-online | https://gist.github.com/mhulse/ce208d2c64f1ce160a6a */ | |
;(function(document, navigator) { | |
!navigator.onLine && (document.documentElement.className = document.documentElement.className.replace(/\bonline\b/, 'not-online')); | |
}(document, navigator)); | |
/*! not-online uglified | https://gist.github.com/mhulse/ce208d2c64f1ce160a6a */!function(document,navigator){!navigator.onLine&&(document.documentElement.className=document.documentElement.className.replace(/\bonline\b/,"not-online"))}(document,navigator); |
This file contains hidden or 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
<!doctype html> | |
<html class=online lang=en> | |
<head> | |
<meta charset=utf-8> | |
<script>/*! not-online uglified | https://gist.github.com/mhulse/ce208d2c64f1ce160a6a */!function(document,navigator){!navigator.onLine&&(document.documentElement.className=document.documentElement.className.replace(/\bonline\b/,"not-online"))}(document,navigator);</script> | |
<title>blah</title> | |
<style> | |
.not-online .msg { text-indent: -9999em; line-height: 0; display: inline-block; } | |
.not-online .msg::after { content: "offline"; text-indent: 0; line-height: initial; display: block; } | |
</style> | |
</head> | |
<body> | |
<p>We’re <span class=msg>online</span>!</p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See also:
no-x.js