如何让我的Popover脚本转向Popunder脚本?

时间:2015-04-20 07:56:38

标签: javascript jquery

我试图将我的popover脚本转换为popunder。

我尝试删除.focus但它没有用。我也试过了.blur,但它也没有用。

你知道其他任何做法吗?

var exoUrl = 'google.com';
var cookieName = 'splashWeb-943108';
var baseDomain = '';

var _top = null;

function getPuId() {
    return "ad_" + Math.floor(89999999 * Math.random() + 10000000)
}

function addEvent(obj, type, fn) {
    if (obj.addEventListener) {
        obj.addEventListener(type, fn, false)
    } else if (obj.attachEvent) {
        obj["e" + type + fn] = fn;
        obj[type + fn] = function () {
            obj["e" + type + fn](window.event)
        };
        obj.attachEvent("on" + type, obj[type + fn])
    } else {
        obj["on" + type] = obj["e" + type + fn]
    }
}
Date.prototype.addHours = function (h) {
    this.setHours(this.getHours() + h);
    return this
};

function setCookie(c_name, value, exdays) {
    var exdate = new Date();
    exdate.addHours(12);
    var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString()) + "; domain=" + baseDomain + "; path=/";
    document.cookie = c_name + "=" + c_value
}

function getCookie(c_name) {
    var i, x, y, ARRcookies = document.cookie.split(";");
    for (i = 0; i < ARRcookies.length; i++) {
        x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
        y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
        x = x.replace(/^\s+|\s+$/g, "");
        if (x == c_name) {
            return unescape(y)
        }
    }
}
var exopop = {
    settings: {
        width: 1024,
        height: 768
    },
    init: function () {
        var browser = exopop.browser;
        _top = self;
        if (top != self) {
            try {
                if (top.document.location.toString()) {
                    _top = top
                }
            } catch (err) {}
        }
        if (browser.isMobile.any(_top)) {
            console.log('mobile');
            exopop.binders.mobile();
            return
        }
        if (browser.is.msie) {
            exopop.binders.firefox();
            return
        }
        if (browser.is.firefox) {
            exopop.binders.firefox();
            return
        }
        if (browser.is.chrome && browser.versionFrom(33) && navigator.appVersion.indexOf("Mac") != -1) {
            exopop.binders.chrome31();
            return
        }
        if (browser.is.chrome && browser.versionFrom(30) && navigator.appVersion.indexOf("Mac") != -1) {
            exopop.binders.chrome30_mac();
            return
        }
        if (browser.is.chrome && browser.versionOlderThan(30)) {
            exopop.binders.chromeUntil30();
            return
        }
        if (browser.is.chrome && browser.versionIs(30)) {
            exopop.binders.chrome30();
            return
        }
        if (browser.is.chrome && browser.versionFrom(31)) {
            exopop.binders.chrome31();
            return
        }
        if (browser.is.safari) {
            exopop.binders.safari();
            return
        }
        exopop.binders.firefox();
        return
    },
    windowParams: function () {
        return 'width=' + exopop.settings.width + ',height=' + exopop.settings.height + ',top=0,left=0,scrollbars=1,location=1,toolbar=0,menubar=0,resizable=1,statusbar=1'
    },
    status: {
        opened: false
    },
    opened: function () {
        if (exopop.status.opened) return false;
        if (getCookie(cookieName)) return true;
        return false
    },
    setAsOpened: function () {
        this.status.opened = false;
        setCookie(cookieName, 1, 1)
    },
    findParentLink: function (clickedElement) {
        var currentElement = clickedElement;
        if (currentElement.getAttribute("target") == null && currentElement.nodeName.toLowerCase() != "html") {
            var o = 0;
            while (currentElement.parentNode && o <= 4 && currentElement.nodeName.toLowerCase() != "html") {
                o++;
                currentElement = currentElement.parentNode;
                if (currentElement.nodeName.toLowerCase() === "a" && currentElement.href != "") {
                    break
                }
            }
        }
        return currentElement
    },
    triggers: {
        firefox: function () {
            if (exopop.opened()) return false;
            var popURL = "about:blank";
            var params = exopop.windowParams();
            var PopWin = _top.window.open(popURL, getPuId(), params);
            if (PopWin) {
                PopWin.blur();
                if (navigator.userAgent.toLowerCase().indexOf("applewebkit") > -1) {
                    _top.window.blur();
                    _top.window.blur()
                }
                PopWin.Init = function (e) {
                    with(e) {
                        Params = e.Params;
                        Main = function () {
                            var x, popURL = Params.PopURL;
                            if (typeof window.mozPaintCount != "undefined") {
                                x = window.open("about:blank");
                                x.close()
                            } else if (navigator.userAgent.toLowerCase().indexOf("chrome/2") > -1) {
                                x = window.open("about:blank");
                                x.close()
                            }
                            try {
                                opener.window.blur()
                            } catch (err) {}
                            window.location = popURL;
                            window.blur()
                        };
                        Main()
                    }
                };
                PopWin.Params = {
                    PopURL: exoUrl
                };
                PopWin.Init(PopWin)
            }
            exopop.setAsOpened();
            return
        },
        chromeUntil30: function () {
            if (exopop.opened()) return false;
            window.open('javascript:window.blur()', '_self');
            var w = window.open('about:blank', getPuId(), exopop.windowParams());
            var a = document.createElement('a');
            a.setAttribute('href', 'data:text/html,<scr' + 'ipt>window.close();</scr' + 'ipt>');
            a.style.display = 'none';
            document.body.appendChild(a);
            var e = document.createEvent('MouseEvents');
            e.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, true, false, false, true, 0, null);
            a.dispatchEvent(e);
            document.body.removeChild(a);
            w.document.open().write('<script type="text/javascript">window.location="' + exoUrl + '";<\/script>');
            w.document.close();
            exopop.setAsOpened()
        },
        chrome30: function (W) {
            if (exopop.opened()) return false;
            var link = document.createElement("a");
            link.href = 'javascript:window.open("' + exoUrl + '","' + getPuId() + '","' + exopop.windowParams() + '")';
            document.body.appendChild(link);
            link.webkitRequestFullscreen();
            var event = document.createEvent("MouseEvents");
            event.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, true, false, 0, null);
            link.dispatchEvent(event);
            document.webkitCancelFullScreen();
            setTimeout(function () {
                window.getSelection().empty()
            }, 250);
            var Z = W.target || W.srcElement;
            Z.click();
            exopop.setAsOpened()
        },
        safari: function () {
            if (exopop.opened()) return false;
            var popWindow = _top.window.open(exoUrl, getPuId(), exopop.windowParams());
            if (popWindow) {
                popWindow.blur();
                popWindow.opener.window.blur();
                window.self.window.blur();
                window.blur();
                var P = "";
                var O = top.window.document.createElement("a");
                O.href = "data:text/html,<scr" + P + "ipt>window.close();</scr" + P + "ipt>";
                document.getElementsByTagName("body")[0].appendChild(O);
                var N = top.window.document.createEvent("MouseEvents");
                N.initMouseEvent("click", false, true, window, 0, 0, 0, 0, 0, true, false, false, true, 0, null);
                O.dispatchEvent(N);
                O.parentNode.removeChild(O)
            }
            exopop.setAsOpened()
        },
        tab: function () {
            if (exopop.opened()) return false;
            var u = (!exoUrl) ? 'data:text/html,<script>window.close();</script>;' : exoUrl;
            var a = top.window.document.createElement("a");
            var e = document.createEvent("MouseEvents");
            a.href = u;
            document.getElementsByTagName("body")[0].appendChild(a);
            e.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, true, false, false, true, 0, null);
            a.dispatchEvent(e);
            a.parentNode.removeChild(a);
            exopop.setAsOpened()
        },
        mobile: function (triggeredEvent) {
            if (exopop.opened()) return false;
            var clickedElement = triggeredEvent.target || triggeredEvent.srcElement;
            if (clickedElement.nodeName.toLowerCase() !== "a") {
                clickedElement = exopop.findParentLink(clickedElement)
            }
            if (clickedElement.nodeName.toLowerCase() === "a" && clickedElement.getAttribute("target") !== "_blank") {
                window.open(clickedElement.getAttribute("href"));
                exopop.setAsOpened();
                _top.document.location = exoUrl;
                if (triggeredEvent.preventDefault != undefined) {
                    triggeredEvent.preventDefault();
                    triggeredEvent.stopPropagation()
                }
                return false
            }
            return true
        }
    },
    binders: {
        explorer: function () {
            addEvent(document, 'click', exopop.triggers.firefox)
        },
        firefox: function () {
            addEvent(document, 'click', exopop.triggers.firefox)
        },
        chromeUntil30: function () {
            addEvent(document, 'mousedown', exopop.triggers.chromeUntil30)
        },
        chrome30: function () {
            addEvent(document, 'mousedown', exopop.triggers.chrome30)
        },
        chrome31: function () {
            addEvent(document, 'mousedown', exopop.triggers.tab)
        },
        chrome30_mac: function () {
            addEvent(document, 'mousedown', exopop.triggers.chromeUntil30)
        },
        safari: function () {
            addEvent(document, 'mousedown', exopop.triggers.safari)
        },
        mobile: function () {
            addEvent(document, 'click', exopop.triggers.mobile)
        }
    },
    browser: {
        is: function () {
            var userAgent = navigator.userAgent.toLowerCase();
            var info = {
                webkit: /webkit/.test(userAgent),
                mozilla: (/mozilla/.test(userAgent)) && (!/(compatible|webkit)/.test(userAgent)),
                chrome: /chrome/.test(userAgent),
                msie: ((/msie/.test(userAgent)) && (!/opera/.test(userAgent)) || (!!navigator.userAgent.match(/Trident.*rv/))),
                firefox: /firefox/.test(userAgent),
                safari: (/safari/.test(userAgent) && !(/chrome/.test(userAgent))),
                opera: /opera/.test(userAgent),
                ie: (!!navigator.userAgent.match(/Trident.*rv/))
            };
            if (info.safari) {
                info.version = (userAgent.match(/.+(?:ri)[\/: ]([\d.]+)/) || [])[1]
            } else if (info.ie) {
                var re = new RegExp("trident/.*rv:([0-9]{1,}[\.0-9]{0,})");
                info.version = (re.exec(userAgent) != null) ? parseFloat(RegExp.$1) : null
            } else {
                info.version = (userAgent.match(/.+(?:ox|me|ra|ie)[\/: ]([\d.]+)/) || [])[1]
            }
            return info
        }(),
        versionNewerThan: function (version) {
            currentVersion = parseInt(this.is.version.split('.')[0]);
            return currentVersion > version
        },
        versionFrom: function (version) {
            currentVersion = parseInt(this.is.version.split('.')[0]);
            return currentVersion >= version
        },
        versionOlderThan: function (version) {
            currentVersion = parseInt(this.is.version.split('.')[0]);
            return currentVersion < version
        },
        versionIs: function (version) {
            currentVersion = parseInt(this.is.version.split('.')[0]);
            return currentVersion == version
        },
        isMobile: {
            Android: function (a) {
                return a.navigator.userAgent.match(/Android/i)
            },
            BlackBerry: function (a) {
                return a.navigator.userAgent.match(/BlackBerry/i)
            },
            iOS: function (a) {
                return a.navigator.userAgent.match(/iPhone|iPad|iPod/i)
            },
            Opera: function (a) {
                return a.navigator.userAgent.match(/Opera Mini/i)
            },
            Windows: function (a) {
                return a.navigator.userAgent.match(/IEMobile/i)
            },
            any: function (a) {
                return a.navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)
            }
        }
    }
};
exopop.init();

0 个答案:

没有答案