SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    May 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Popunder that works well for all browser

    Here is one popunder code that works well:
    Code:
    function makePopunder(pUrl) {
        var _parent = (top != self && typeof (top["document"]["location"].toString()) === "string") ? top : self;
        var mypopunder = null;
        var pName = (Math["floor"]((Math["random"]() * 1000) + 1));
        var pWidth = window["innerWidth"];
        var pHeight = window["innerHeight"];
        var pPosX = window["screenX"];
        var pPosY = window["screenY"];
        var pWait = 3600;
        pWait = (pWait * 1000);
        var pCap = 50000;
        var todayPops = 0;
        var cookie = "_.mypopunder";
        var browser = function () {
            var n = navigator["userAgent"]["toLowerCase"]();
            var b = {
                webkit: /webkit/ ["test"](n),
                mozilla: (/mozilla/ ["test"](n)) && (!/(compatible|webkit)/ ["test"](n)),
                chrome: /chrome/ ["test"](n),
                msie: (/msie/ ["test"](n)) && (!/opera/ ["test"](n)),
                firefox: /firefox/ ["test"](n),
                safari: (/safari/ ["test"](n) && !(/chrome/ ["test"](n))),
                opera: /opera/ ["test"](n)
            };
            b["version"] = (b["safari"]) ? (n["match"](/.+(?:ri)[\/: ]([\d.]+)/) || [])[1] : (n["match"](/.+(?:ox|me|ra|ie)[\/: ]([\d.]+)/) || [])[1];
            return b;
        }();
    
        function isCapped() {
            try {
                todayPops = Math["floor"](document["cookie"]["split"](cookie + "Cap=")[1]["split"](";")[0]);
            } catch (err) {};
            return (pCap <= todayPops || document["cookie"]["indexOf"](cookie + "=") !== -1);
        };
    
        function doPopunder(pUrl, pName, pWidth, pHeight, pPosX, pPosY) {
            if (isCapped()) {
                return;
            };
            var sOptions = "toolbar=no,scrollbars=yes,location=yes,statusbar=yes,menubar=no,resizable=1,width=" + pWidth.toString() + ",height=" + pHeight.toString() + ",screenX=" + pPosX + ",screenY=" + pPosY;
            document["onclick"] = function (e) {
                if (isCapped() || window["pop_clicked"] == 1 || pop_isRightButtonClicked(e)) {
                    //return;
                };
                window["pop_clicked"] = 1;
                mypopunder = _parent["window"]["open"](pUrl, pName, sOptions);
                if (mypopunder) {
                    var now = new Date();
                    document["cookie"] = cookie + "=1;expires=" + new Date(now["setTime"](now["getTime"]() + pWait))["toGMTString"]() + ";path=/";
                    now = new Date();
                    document["cookie"] = cookie + "Cap=" + (todayPops + 1) + ";expires=" + new Date(now["setTime"](now["getTime"]() + (84600 * 1000)))["toGMTString"]() + ";path=/";
                    pop2under();
                };
            };
        };
    
        function pop2under() {
            try {
                mypopunder["blur"]();
                mypopunder["opener"]["window"]["focus"]();
                window["self"]["window"]["blur"]();
                window["focus"]();
                if (browser["firefox"]) {
                    openCloseWindow();
                };
                if (browser["webkit"]) {
                    openCloseTab();
                };
            } catch (e) {};
        };
    
        function openCloseWindow() {
            var ghost = window["open"]("about:blank");
            ghost["focus"]();
            ghost["close"]();
        };
    
        function openCloseTab() {
            var ghost = document["createElement"]("a");
            ghost["href"] = "about:blank";
            ghost["target"] = "PopHelper";
            document["getElementsByTagName"]("body")[0]["appendChild"](ghost);
            ghost["parentNode"]["removeChild"](ghost);
            var clk = document["createEvent"]("MouseEvents");
            clk["initMouseEvent"]("click", true, true, window, 0, 0, 0, 0, 0, true, false, false, true, 0, null);
            ghost["dispatchEvent"](clk);
            window["open"]("about:blank", "PopHelper")["close"]();
        };
    
        function pop_isRightButtonClicked(e) {
            var rightclick = false;
            e = e || window["event"];
            if (e["which"]) {
                rightclick = (e["which"] == 3);
            } else {
                if (e["button"]) {
                    rightclick = (e["button"] == 2);
                };
            };
            return rightclick;
        };
        if (isCapped()) {
            return;
        } else {
            doPopunder(pUrl, pName, pWidth, pHeight, pPosX, pPosY);
        };
    }
    
    makePopunder("http://www.yourdomain.com/");
    Last edited by Force Flow; Apr 22, 2013 at 07:54. Reason: added code tags

  2. #2
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,606
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    Do you have a question?
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  3. #3
    SitePoint Member
    Join Date
    May 2014
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you very much for your code.
    Could you provide us with more information about the constants like
    pCap = 50000;
    todayPops = 0;
    how can i use them?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •