Skip to content

Instantly share code, notes, and snippets.

@yllus
Last active August 29, 2015 14:19
Show Gist options
  • Select an option

  • Save yllus/f933f83303f689a13d90 to your computer and use it in GitHub Desktop.

Select an option

Save yllus/f933f83303f689a13d90 to your computer and use it in GitHub Desktop.
Only display the loyalty mobile warning once every 2 days (setting a cookie)
<!-- Loyalty mobile warning -->
<script>
$(document).ready(function() {
var isMobile = window.matchMedia("only screen and (max-width: 760px)");
var isCookieSet = getCookie('loyalty_mobile_warning');
if (isMobile.matches && isCookieSet === false) {
setCookie('loyalty_mobile_warning', '1', 2);
alert("The 680 NEWS Insider Club is optimized to work best on a computer or tablet. Please log in using one of those devices. If you are on a smartphone, rotate it to landscape mode.")
}
});
function getCookie( cname ) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
}
return false;
}
function setCookie( cname, cvalue, exdays ) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment