View Single Post
Old 06-28-2012, 10:53 AM  
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,233
jquery alternative to a popunder for those who want it.

hope this is of use to someone

jquery.popunder.js way (download link) https://github.com/chrismccoy/jquery.popunder

Code:
$.popunder('http://google.com',24); // once every 24 hours
$.popunder('http://google.com',0); // reset when browser closes
$.popunder('http://google.com'); // every time
full html example

Code:
!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jquery.popunder.js</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.cookies.js"></script>
<script type="text/javascript" src="js/jquery.popunder.js"></script>
<script type="text/javascript">
jQuery(document).ready(function ($) { 
	$(document).click(function () { 
        	$.popunder('http://google.com',24); // once every 24 hours
	}); 
});
</script>
</head>

<body>

</body>
</html>
Here is a previous method of doing a popunder.

Code:
var Popup = {

    AddListener: function(target, eventName, handler) {
        if (eventName == "beforeunload" || eventName == "unload") {
            var originalHandler = target["on" + eventName];
            if (originalHandler) {
                target["on" + eventName] = function(e) {
                    var ret = originalHandler(e);
                    if (typeof(ret) == "undefined" || ret == "") ret = handler(e);
                    return ret;
                };
            } else {
                target["on" + eventName] = handler;
            }
        } else if (target.addEventListener) {
            target.addEventListener(eventName, handler, false);
        } else if (target.attachEvent) {
            target.attachEvent("on" + eventName, handler);
        } else {
            var originalHandler = target["on" + eventName];
            if (originalHandler) {
                target["on" + eventName] = function(e) {
                    originalHandler(e);
                    handler(e);
                };
            } else {
                target["on" + eventName] = handler;
            }
        }
    },

    CreatePop: function(e) {


        var popURL = "about:blank"
        var popID = "ad_" + Math.floor(89999999 * Math.random() + 10000000);
        var pxLeft = 0;
        var pxTop = 0;

        // Place the window coordinates in the center of the active window
        pxLeft = (this.GetWindowLeft() + (this.GetWindowWidth() / 2) - (this.PopWidth / 2));
        pxTop = (this.GetWindowTop() + (this.GetWindowHeight() / 2) - (this.PopHeight / 2));

        // Create the popup
        this.PopWin = this.Window.open(popURL, popID, 'toolbar=0,scrollbars=1,location=1,statusbar=1,menubar=0,resizable=1,top=' + pxTop + ',left=' + pxLeft + ',width=' + this.PopWidth + ',height=' + this.PopHeight);

        if (this.PopWin) {


            // We don't want to pop again on the same pop load.
            this.PopLoaded = true;

            // Increment the successfull pop count cookie
            this.SetPoppedTotal();

            // Make the popup show either in front or behind the page
            if (this.PopFocus == 0) {
                this.PopWin.blur();

                if (navigator.userAgent.toLowerCase().indexOf("applewebkit") > -1) {
                    this.Window.blur();
                    this.Window.focus();
                }
            }

            // Load the url in the placeholder window
            this.PopWin.Init = function(e) {

                with(e) {

                    this.Params = e.Params; // IE9 Bugfix. "this" not functioning properly
                    // Main code function
                    this.Main = function() {

                        if (typeof window.mozPaintCount != "undefined") {
                            var x = this.window.open("about:blank");
                            x.close();
                        }

                        // Set the parameters in the local scope
                        var popURL = this.Params.PopURL;

                        try {
                            opener.window.focus();
                        } catch (err) {}

                        window.location = popURL;
                    }

                    this.Main();
                }
            };

            this.PopWin.Params = {
                PopURL: this.PopURL
            }

            this.PopWin.Init(this.PopWin);
        }

        return true;
    },

    GetWindowHeight: function() {

        var myHeight = 0;

        if (typeof(this.Window.innerHeight) == 'number') {
            //Non-IE
            myHeight = this.Window.innerHeight;
        } else if (this.Window.document.documentElement && this.Window.document.documentElement.clientHeight) {
            //IE 6+ in 'standards compliant mode'
            myHeight = this.Window.document.documentElement.clientHeight;
        } else if (this.Window.document.body && this.Window.document.body.clientHeight) {
            //IE 4 compatible
            myHeight = this.Window.document.body.clientHeight;
        }

        return myHeight;

    },

    GetWindowWidth: function() {

        var myWidth = 0;

        if (typeof(this.Window.innerWidth) == 'number') {
            //Non-IE
            myWidth = this.Window.innerWidth;
        } else if (this.Window.document.documentElement && this.Window.document.documentElement.clientWidth) {
            //IE 6+ in 'standards compliant mode'
            myWidth = this.Window.document.documentElement.clientWidth;
        } else if (this.Window.document.body && this.Window.document.body.clientWidth) {
            //IE 4 compatible
            myWidth = this.Window.document.body.clientWidth;
        }

        return myWidth;
    },

    GetWindowTop: function() {
        return (this.Window.screenTop != undefined) ? this.Window.screenTop : this.Window.screenY;
    },

    GetWindowLeft: function() {
        return (this.Window.screenLeft != undefined) ? this.Window.screenLeft : this.Window.screenX;
    },
    InitPop: function(e) {

        // Allow one pop per page, prevent double execution
        if (this.PopLoaded || arguments.callee.init) return true;

        // Double check to see if the pop cap has been reached
        if (this.GetPoppedTotal() >= this.PopFreq) return true;

        arguments.callee.init = true;

        var status = this.CreatePop(e);

        arguments.callee.init = false;

        return status;
    },
    Watch: function(ctx, options) {

        for (var i in options) {
            this[i] = options[i];
        }
        this.Window = ctx;
        Popup.AddListener(this.Window.document, "click", function(e) {
            if (!Popup.InitPop(e)) {
                if (e.preventDefault) {
                    e.preventDefault()
                }
                e.returnValue = false;
            }
        });
    },
    CreateCookie: function(name, value, days) {

        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
            var expires = "; expires=" + date.toGMTString();
        } else var expires = "";
        this.Window.document.cookie = name + "=" + value + expires + "; path=/";
    },


    ReadCookie: function(name) {

        var ca = this.Window.document.cookie.split(';');
        var nameEQ = name + "=";
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') c = c.substring(1, c.length); //delete spaces
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
        }
        return null;
    },

    GetPoppedTotal: function() {

        var popTotal = this.ReadCookie(this.CookieName);
        popTotal = (popTotal != null) ? parseInt(popTotal) : 0;

        return popTotal;
    },

    SetPoppedTotal: function() {

        var popTotal = this.ReadCookie(this.CookieName);

        if (popTotal != null) this.CreateCookie(this.CookieName, parseInt(popTotal) + 1, 1);
        else this.CreateCookie(this.CookieName, 1, 1);
    }

}


var PopUpConfig = {
    CookieName: "goog",
    PopFocus: 0,
    PopURL: "http://www.google.com",
    PopFreq: 1,
    PopWidth: 1024,
    PopHeight: 764
}

Popup.Watch(window, PopUpConfig);
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


WP Stuff
fris is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote