Last active
June 21, 2017 20:53
-
-
Save xy0/09e0f9e1471f68cf916f368a34f01ea6 to your computer and use it in GitHub Desktop.
Simple javascript popup that requires the user to select yes or no, then saves a cookie and won't show up again
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
<div id="o98uy5eiofg" style="background-color:#2c2d30cc;position:fixed;left:0;right:0;bottom:0;top:0;z-index: 900;"></div> | |
<style> | |
body { | |
overflow: hidden; | |
} | |
div.popup { | |
position: fixed; | |
left: 50%; | |
top: 50%; | |
width: 400px; | |
height: 300px; | |
margin-left: -200px; | |
margin-top: -150px; | |
background: white; | |
-moz-border-radius: 10px; | |
-webkit-border-radius: 10px; | |
-khtml-border-radius: 10px; | |
border-radius: 10px; | |
padding: 10px; | |
z-index: 901; | |
text-align: center; | |
padding: 87px; | |
} | |
} | |
</style> | |
<div id="p908357te3" class="popup"> | |
<h3 style="">Are you a legally able to view this page?</h3> <button id="j39gjhsd" class="btn btn-default" style="margin: 10px;" type="submit">Yes</button><button id="j309sdjfg9" class="btn btn-default" style="margin: 10px;" type="submit">No</button></div> | |
<script> | |
function createCookie(name, value, days) { | |
if (days) { | |
var date = new Date(); | |
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); | |
var expires = "; expires=" + date.toGMTString(); | |
} else var expires = ""; | |
document.cookie = name + "=" + value + expires + "; path=/"; | |
} | |
function readCookie(name) { | |
var nameEQ = name + "="; | |
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, c.length); | |
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); | |
} | |
return null; | |
} | |
if (readCookie('hoee89ph')) { | |
$('#o98uy5eiofg').remove(); | |
$('#p908357te3').remove(); | |
$("body").css({ | |
overflow: 'auto' | |
}); | |
} | |
$('#j39gjhsd').click(function() { | |
$('#o98uy5eiofg').remove(); | |
$('#p908357te3').remove(); | |
$("body").css({ | |
overflow: 'auto' | |
}); | |
createCookie('hoee89ph', 'p0w39g98uj4', 365); | |
}); | |
$('#j309sdjfg9').click(function() { | |
$('#p908357te3').html('Thank you but click here to go somewhere else <a>sorry</a>'); | |
}) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment