Skip to content

Instantly share code, notes, and snippets.

@hpbuniat
Created March 17, 2012 12:18
Show Gist options
  • Select an option

  • Save hpbuniat/2058263 to your computer and use it in GitHub Desktop.

Select an option

Save hpbuniat/2058263 to your computer and use it in GitHub Desktop.

Revisions

  1. hpbuniat revised this gist May 8, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion popunder.html
    Original file line number Diff line number Diff line change
    @@ -90,7 +90,7 @@
    */
    open: function(sUrl, blockTime, bSimple) {
    var _parent = self,
    sToolbar = (!$.browser.webkit && (!$.browser.mozilla || parseInt($.browser.version, 10)) < 12) ? 'yes' : 'no',
    sToolbar = (!$.browser.webkit && (!$.browser.mozilla || parseInt($.browser.version, 10) < 12)) ? 'yes' : 'no',
    sOptions,
    popunder;

  2. hpbuniat revised this gist May 8, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion popunder.html
    Original file line number Diff line number Diff line change
    @@ -90,7 +90,7 @@
    */
    open: function(sUrl, blockTime, bSimple) {
    var _parent = self,
    sToolbar = (!$.browser.mozilla || parseInt($.browser.version, 10) < 12) ? 'yes' : 'no',
    sToolbar = (!$.browser.webkit && (!$.browser.mozilla || parseInt($.browser.version, 10)) < 12) ? 'yes' : 'no',
    sOptions,
    popunder;

  3. hpbuniat revised this gist May 8, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion popunder.html
    Original file line number Diff line number Diff line change
    @@ -90,7 +90,7 @@
    */
    open: function(sUrl, blockTime, bSimple) {
    var _parent = self,
    sToolbar = ($.browser.mozilla && parseInt($.browser.version, 10) < 12) ? 'yes' : 'no',
    sToolbar = (!$.browser.mozilla || parseInt($.browser.version, 10) < 12) ? 'yes' : 'no',
    sOptions,
    popunder;

  4. hpbuniat revised this gist May 5, 2012. 1 changed file with 75 additions and 57 deletions.
    132 changes: 75 additions & 57 deletions popunder.html
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    <meta content="Hans-Peter Buniat" name="author">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Form-Submit Popunder with Cookie support</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

    <!-- Cookie support -->
    <script type="text/javascript" src="https://cookies.googlecode.com/svn/trunk/jaaulde.cookies.js"></script>
    @@ -27,69 +27,20 @@
    * @return jQuery
    */
    $.popunder = function(sUrl, blockTime) {
    var _parent = self,
    bPopunder = ($.browser.msie && parseInt($.browser.version, 10) < 9),
    sOptions,
    popunder;

    if (blockTime && $.popunderHelper.cookieCheck(sUrl, blockTime)) {
    return this;
    }

    if (top != self) {
    try {
    if (top.document.location.toString()) {
    _parent = top;
    }
    }
    catch(err) { }
    }

    /* popunder options */
    sOptions = 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=0,resizable=1,width=' + (screen.availWidth - 10).toString();
    sOptions += ',height=' + (screen.availHeight - 122).toString() + ',screenX=0,screenY=0,left=0,top=0';

    /* create pop-up from parent context */
    popunder = _parent.window.open(sUrl, $.popunderHelper.rand(), sOptions);
    if (popunder) {
    popunder.blur();
    if (bPopunder) {
    /* classic popunder, used for old ie*/
    window.focus();
    try { opener.window.focus(); }
    catch (err) { }
    }
    else {
    /* popunder for e.g. ff4+, chrome, ie9 */
    popunder.init = function(e) {
    with (e) {
    (function() {
    if (typeof window.mozPaintCount != 'undefined') {
    var x = window.open('about:blank');
    x.close();
    }

    try { opener.window.focus(); }
    catch (err) { }
    })();
    }
    };
    popunder.params = {
    url: sUrl
    };
    popunder.init(popunder);
    }
    }

    return this;
    var bSimple = $.browser.msie,
    run = function() {
    $.popunderHelper.open(sUrl, blockTime, bSimple);
    };
    (bSimple) ? run() : window.setTimeout(run, 1);
    return $;
    };

    /* several helper functions */
    $.popunderHelper = {
    /**
    * Helper to create a (optionally) random value with prefix
    *
    * @param int block time in hours
    * @param int blockTime block time in hours
    *
    * @return boolean
    */
    @@ -126,6 +77,73 @@
    rand: function(name, rand) {
    var p = (name) ? name : 'pu_';
    return p + (rand === false ? '' : Math.floor(89999999*Math.random()+10000000));
    },

    /**
    * Open the popunder
    *
    * @param string sUrl The URL to open
    * @param int blockTime block time in hours
    * @param boolean bSimple Use the simple popunder
    *
    * @return boolean
    */
    open: function(sUrl, blockTime, bSimple) {
    var _parent = self,
    sToolbar = ($.browser.mozilla && parseInt($.browser.version, 10) < 12) ? 'yes' : 'no',
    sOptions,
    popunder;

    if (blockTime && $.popunderHelper.cookieCheck(sUrl, blockTime)) {
    return false;
    }

    if (top != self) {
    try {
    if (top.document.location.toString()) {
    _parent = top;
    }
    }
    catch(err) { }
    }

    /* popunder options */
    sOptions = 'toolbar=' + sToolbar + ',scrollbars=yes,location=yes,statusbar=yes,menubar=no,resizable=1,width=' + (screen.availWidth - 10).toString();
    sOptions += ',height=' + (screen.availHeight - 122).toString() + ',screenX=0,screenY=0,left=0,top=0';

    /* create pop-up from parent context */
    popunder = _parent.window.open(sUrl, $.popunderHelper.rand(), sOptions);
    if (popunder) {
    popunder.blur();
    if (bSimple) {
    /* classic popunder, used for ie*/
    window.focus();
    try { opener.window.focus(); }
    catch (err) { }
    }
    else {
    /* popunder for e.g. ff4+, chrome */
    popunder.init = function(e) {
    with (e) {
    (function() {
    if (typeof window.mozPaintCount != 'undefined') {
    var x = window.open('about:blank');
    x.close();
    }

    try { opener.window.focus(); }
    catch (err) { }
    })();
    }
    };
    popunder.params = {
    url: sUrl
    };
    popunder.init(popunder);
    }
    }

    return true;
    }
    };
    })(jQuery);
  5. hpbuniat revised this gist Mar 17, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion popunder.html
    Original file line number Diff line number Diff line change
    @@ -131,7 +131,7 @@
    })(jQuery);

    $('#testSubmit').submit(function() {
    jQuery.popunder('http://www.fluege.de', 1).popunder('http://www.flug24.de', 2);
    jQuery.popunder('http://www.fluege.de', 1).popunder('http://www.flug24.de');
    });
    </script>
    </body>
  6. hpbuniat created this gist Mar 17, 2012.
    138 changes: 138 additions & 0 deletions popunder.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,138 @@
    <!DOCTYPE html>
    <html>
    <head>
    <meta content="Hans-Peter Buniat" name="author">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Form-Submit Popunder with Cookie support</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

    <!-- Cookie support -->
    <script type="text/javascript" src="https://cookies.googlecode.com/svn/trunk/jaaulde.cookies.js"></script>
    <script type="text/javascript" src="https://cookies.googlecode.com/svn/trunk/jquery.cookies.js"></script>
    </head>
    <body>
    <form id="testSubmit" action="http://www.google.com">
    <input type="submit" />
    </form>

    <script type="text/javascript">
    /* use jQuery as container for more convenience */
    (function($) {
    /**
    * Create a popunder
    *
    * @param sUrl Url to open as popunder
    * @param int block time in hours
    *
    * @return jQuery
    */
    $.popunder = function(sUrl, blockTime) {
    var _parent = self,
    bPopunder = ($.browser.msie && parseInt($.browser.version, 10) < 9),
    sOptions,
    popunder;

    if (blockTime && $.popunderHelper.cookieCheck(sUrl, blockTime)) {
    return this;
    }

    if (top != self) {
    try {
    if (top.document.location.toString()) {
    _parent = top;
    }
    }
    catch(err) { }
    }

    /* popunder options */
    sOptions = 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=0,resizable=1,width=' + (screen.availWidth - 10).toString();
    sOptions += ',height=' + (screen.availHeight - 122).toString() + ',screenX=0,screenY=0,left=0,top=0';

    /* create pop-up from parent context */
    popunder = _parent.window.open(sUrl, $.popunderHelper.rand(), sOptions);
    if (popunder) {
    popunder.blur();
    if (bPopunder) {
    /* classic popunder, used for old ie*/
    window.focus();
    try { opener.window.focus(); }
    catch (err) { }
    }
    else {
    /* popunder for e.g. ff4+, chrome, ie9 */
    popunder.init = function(e) {
    with (e) {
    (function() {
    if (typeof window.mozPaintCount != 'undefined') {
    var x = window.open('about:blank');
    x.close();
    }

    try { opener.window.focus(); }
    catch (err) { }
    })();
    }
    };
    popunder.params = {
    url: sUrl
    };
    popunder.init(popunder);
    }
    }

    return this;
    };

    /* several helper functions */
    $.popunderHelper = {
    /**
    * Helper to create a (optionally) random value with prefix
    *
    * @param int block time in hours
    *
    * @return boolean
    */
    cookieCheck: function(sUrl, blockTime) {
    var name = this.rand('puCookie', false);
    cookie = $.cookies.get(name),
    ret = false;

    if (!cookie) {
    cookie = sUrl;
    }
    else if (cookie.indexOf(sUrl) === -1) {
    cookie += sUrl;
    }
    else {
    ret = true;
    }

    $.cookies.set(name, cookie, {
    expiresAt: new Date((new Date()).getTime() + blockTime * 3600000)
    });

    return ret;
    },

    /**
    * Helper to create a (optionally) random value with prefix
    *
    * @param string name
    * @param boolean rand
    *
    * @return string
    */
    rand: function(name, rand) {
    var p = (name) ? name : 'pu_';
    return p + (rand === false ? '' : Math.floor(89999999*Math.random()+10000000));
    }
    };
    })(jQuery);

    $('#testSubmit').submit(function() {
    jQuery.popunder('http://www.fluege.de', 1).popunder('http://www.flug24.de', 2);
    });
    </script>
    </body>
    </html>