Created
June 28, 2012 23:38
-
-
Save cam-gists/3014754 to your computer and use it in GitHub Desktop.
JavaScript: Popunder
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
var PopURL = 'http://www.google.com'; | |
var PopWidth = 1100; | |
var PopHeight = 700; | |
var PopCookieTimeout = 3600; | |
// TH - Popper Date 6-28-2012 | |
// | |
var P = false; | |
var W = 0; | |
var B = null; | |
var site = window.location.host; | |
function Z() { | |
var myHeight = 0; | |
if (typeof B.window.innerHeight == "number") { | |
myHeight = B.window.innerHeight; | |
} else if (B.document.documentElement && B.document.documentElement.clientHeight) { | |
myHeight = B.document.documentElement.clientHeight; | |
} else if (B.document.body && B.document.body.clientHeight) { | |
myHeight = B.document.body.clientHeight; | |
} | |
return myHeight; | |
}function U() { | |
var D = 0; | |
if (typeof B.window.innerWidth == "number") { | |
D = B.window.innerWidth; | |
} else if (B.document.documentElement && B.document.documentElement.clientWidth) { | |
D = B.document.documentElement.clientWidth; | |
} else if (B.document.body && B.document.body.clientWidth) { | |
D = B.document.body.clientWidth; | |
} | |
return D; | |
}function S() { | |
return B.window.screenTop != undefined ? B.window.screenTop : B.window.screenY; | |
}function c() { | |
return B.window.screenLeft != undefined ? B.window.screenLeft : B.window.screenX; | |
}function j(url) { | |
var popURL = "about:blank"; | |
var a = "ad_" + Math.floor(89999999 * Math.random() + 10000000); | |
var O = 0; | |
var N = 0; | |
O = c() + U() / 2 - PopWidth / 2; | |
N = S() + Z() / 2 - PopHeight / 2; | |
if (P == true) { | |
return true; | |
} | |
var C = B.window.open(popURL, a, "toolbar=0,scrollbars=1,location=1,statusbar=1,menubar=0,resizable=1,top=" + N + ",left=" + O + ",width=" + PopWidth + ",height=" + PopHeight); | |
if (C) { | |
P = true; | |
if (W == 0) { | |
C.blur(); | |
if (navigator.userAgent.toLowerCase().indexOf("applewebkit") > -1) { | |
B.window.blur(); | |
B.window.focus(); | |
} | |
} | |
C.h = function (e) { | |
with(e) { | |
I = e.I; | |
i = function () { | |
if (typeof window.k != "undefined") { | |
var x = window.open("about:blank"); | |
x.close(); | |
} | |
var popURL = I.PopURL; | |
try { | |
opener.window.focus(); | |
} catch (g) {} | |
window.location = popURL; | |
}; | |
i(); | |
} | |
}; | |
C.I = { | |
PopURL: url | |
}; | |
C.h(C); | |
} | |
return C; | |
}function b(name, value, T) { | |
var expires = new Date; | |
expires.setTime(expires.getTime() + T); | |
document.cookie = name + "=" + value + "; path=/;" + "; expires=" + expires.toGMTString(); | |
}function R(name) { | |
var cookies = document.cookie.toString().split("; "); | |
var cookie, M, K; | |
for (var H = 0; H < cookies.length; H++) { | |
cookie = cookies[H].split("="); | |
M = cookie[0]; | |
K = cookie[1]; | |
if (M == name) { | |
return K; | |
} | |
} | |
return null; | |
}function V() { | |
B = self; | |
if (top != self) { | |
try { | |
if (top.document.location.toString()) { | |
B = top; | |
} | |
} catch (g) {} | |
} | |
if (document.attachEvent) { | |
document.attachEvent("onclick", L); | |
} else if (document.addEventListener) { | |
document.addEventListener("click", L, false); | |
} | |
}function L(e) { | |
if (!R(site + "-popper") || PopCookieTimeout == 0) { | |
var e = e || window.event; | |
var l = j(PopURL); | |
b(site + "-popper", 1, PopCookieTimeout * 1000); | |
} | |
} | |
V(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment