Last active
August 29, 2015 14:19
-
-
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)
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
| <!-- 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