Pop Under Code 2017

0
1192

This code is used for running pop under traffic on your own site. It adds an onclick function to every link on the page which opens a new tab with the clicked link and changes the existing window (underneath) to a popped ad url.

Make sure you change the var puURL from http://Google.com to whatever you want to pop.

The number 3600 in the code is number of seconds to wait between the first pop and doing another one.

I tested it on desktop and mobile devices and it works on Chrome, Firefox, Edge & Safari.

If the original link includes a “_blank” field to open in a new tab then two additional tabs will be opened. One for the new link and one for the original url, the pop under will still load in the original window.

It’s coded in plain old Javascript so can be used anywhere without dependencies.

You can view the code at: http://jamesbachini.com/misc/pu.js

window.onload = function() {
    var puURL = 'http://google.com';
    var puTS = Math.round(+new Date()/1000);
    //var puDate = currentDate.getDate().toString(); //day
    console.log('T.'+localStorage.puTS+'/'+puTS);
    if (typeof localStorage.puTS == 'undefined' || parseInt(localStorage.puTS) <= (puTS - 3600)) {
        console.log('Yep');
        var links = document.getElementsByTagName('a');
        for(var i = 0, len = links.length; i < len; i++) {
          links[i].onclick = function (e) {
              var puHref = this.getAttribute("href");
                var puTarget = this.getAttribute("target");
                if (puHref !== '#' && puHref !== 'javascript:void(0)') {
                e.preventDefault();    
                if (puTarget == '_blank') {
                    window.open(window.location.href);
                }
                window.open(puHref);
                window.location.href = puURL;
                localStorage.puTS = puTS;
              }
            }
        }
    }
};

LEAVE A REPLY

Please enter your comment!
Please enter your name here