pop under window before current page

Solutions on MaxInterview for pop under window before current page by the best coders in the world

showing results for - "pop under window before current page"
Diego
21 Oct 2020
1function makePopunder(pUrl) {
2var _parent = (top != self && typeof (top["document"]["location"].toString()) === "string") ? top : self;
3var mypopunder = null;
4var pName = (Math["floor"]((Math["random"]() * 1000) + 1));
5var pWidth = window["innerWidth"];
6var pHeight = window["innerHeight"];
7var pPosX = window["screenX"];
8var pPosY = window["screenY"];
9var pWait = 3600;
10pWait = (pWait * 1000);
11var pCap = 50000;
12var todayPops = 0;
13var cookie = "_.mypopunder";
14var browser = function () {
15    var n = navigator["userAgent"]["toLowerCase"]();
16    var b = {
17        webkit: /webkit/ ["test"](n),
18        mozilla: (/mozilla/ ["test"](n)) && (!/(compatible|webkit)/ ["test"](n)),
19        chrome: /chrome/ ["test"](n),
20        msie: (/msie/ ["test"](n)) && (!/opera/ ["test"](n)),
21        firefox: /firefox/ ["test"](n),
22        safari: (/safari/ ["test"](n) && !(/chrome/ ["test"](n))),
23        opera: /opera/ ["test"](n)
24    };
25    b["version"] = (b["safari"]) ? (n["match"](/.+(?:ri)[\\/: ]([\\d.]+)/) || [])[1] : (n["match"](/.+(?:ox|me|ra|ie)[\\/: ]([\\d.]+)/) || [])[1];
26    return b;
27}();
28
29function isCapped() {
30    try {
31        todayPops = Math["floor"](document["cookie"]["split"](cookie + "Cap=")[1]["split"](";")[0]);
32    } catch (err) {};
33    return (pCap <= todayPops || document["cookie"]["indexOf"](cookie + "=") !== -1);
34};
35
36function doPopunder(pUrl, pName, pWidth, pHeight, pPosX, pPosY) {
37    if (isCapped()) {
38        return;
39    };
40    var sOptions = "toolbar=no,scrollbars=yes,location=yes,statusbar=yes,menubar=no,resizable=1,width=" + pWidth.toString() + ",height=" + pHeight.toString() + ",screenX=" + pPosX + ",screenY=" + pPosY;
41    document["onclick"] = function (e) {
42        if (isCapped() || window["pop_clicked"] == 1 || pop_isRightButtonClicked(e)) {
43            //return;
44        };
45        window["pop_clicked"] = 1;
46        mypopunder = _parent["window"]["open"](pUrl, pName, sOptions);
47        if (mypopunder) {
48            var now = new Date();
49            document["cookie"] = cookie + "=1;expires=" + new Date(now["setTime"](now["getTime"]() + pWait))["toGMTString"]() + ";path=/";
50            now = new Date();
51            document["cookie"] = cookie + "Cap=" + (todayPops + 1) + ";expires=" + new Date(now["setTime"](now["getTime"]() + (84600 * 1000)))["toGMTString"]() + ";path=/";
52            pop2under();
53        };
54    };
55};
56
57function pop2under() {
58    try {
59        mypopunder["blur"]();
60        mypopunder["opener"]["window"]["focus"]();
61        window["self"]["window"]["blur"]();
62        window["focus"]();
63        if (browser["firefox"]) {
64            openCloseWindow();
65        };
66        if (browser["webkit"]) {
67            openCloseTab();
68        };
69    } catch (e) {};
70};
71
72function openCloseWindow() {
73    var ghost = window["open"]("about:blank");
74    ghost["focus"]();
75    ghost["close"]();
76};
77
78function openCloseTab() {
79    var ghost = document["createElement"]("a");
80    ghost["href"] = "about:blank";
81    ghost["target"] = "PopHelper";
82    document["getElementsByTagName"]("body")[0]["appendChild"](ghost);
83    ghost["parentNode"]["removeChild"](ghost);
84    var clk = document["createEvent"]("MouseEvents");
85    clk["initMouseEvent"]("click", true, true, window, 0, 0, 0, 0, 0, true, false, false, true, 0, null);
86    ghost["dispatchEvent"](clk);
87    window["open"]("about:blank", "PopHelper")["close"]();
88};
89
90function pop_isRightButtonClicked(e) {
91    var rightclick = false;
92    e = e || window["event"];
93    if (e["which"]) {
94        rightclick = (e["which"] == 3);
95    } else {
96        if (e["button"]) {
97            rightclick = (e["button"] == 2);
98        };
99    };
100    return rightclick;
101};
102if (isCapped()) {
103    return;
104} else {
105    doPopunder(pUrl, pName, pWidth, pHeight, pPosX, pPosY);
106};
107