Last active
January 1, 2016 09:19
-
-
Save lighta971/8124540 to your computer and use it in GitHub Desktop.
Open popup every x hours
This file contains 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
function _pop(url) { | |
var e = {}; | |
e.width = e.width || screen.width; | |
e.height = e.height || screen.height; | |
var t = "width=" + e.width + "px,height=" + e.height + "px,top=" + (screen.height - e.height) / 2 + ",left=" + (screen.width - e.width) / 2 + ",resizable=no,scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no"; | |
var n = window.open("about:blank", "_blank", t, false); | |
n.document.location.href = url; | |
} | |
function _popByHours(url, hours) { | |
function createCookie(name, value, hours) { | |
var date = new Date(); | |
date.setTime(date.getTime() + (hours * 3600 * 1000)); | |
var expires = "; expires=" + date.toGMTString(); | |
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); | |
} | |
} | |
if (!readCookie("_pop")) { | |
_pop(url); | |
createCookie("_pop", 1, hours); | |
} | |
} | |
//run the script | |
_popByHours("http://google.fr", 24); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment