How to take referrer of this script? I want it to open when I came from any site

-4

Hello. I have a script, but it only opens when it comes from certain sites. How do I make it open without ever having to referrer and keep cookies? Thanks since.

  function getCookie(c_name) {
    var i, x, y, ARRcookies = document.cookie.split(";");
    for (i = 0; i < ARRcookies.length; i += 1) {
        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))
        }
    }
 }

 // <![CDATA[
jQuery(function() {
    var sel = 'iframe';

    var x = document.referrer;
    var y = x.search("facebook");
    var z = x.search("//t.co");
    var w = x.search("twitter");

    if (((y > 0) || (z > 0) || (w > 0)) && (getCookie('clickedad'))) {
        $(sel).hide();
    }

    $(sel).iframeTracker({
        blurCallback: function() {
            var now = new Date();
            var time = now.getTime();
            time += 12*60*60*1000;
            now.setTime(time);
            document.cookie =
                'clickedad=1' +
                '; expires=' + now.toUTCString() +
                '; path=/';

            $(sel).fadeOut();
            $('#escuro').hide();
            $('#tela').hide();
        }
    });
});
// ]]>

$(function() {

    var x = document.referrer;
    var y = x.search("facebook");
    var z = x.search("//t.co");
    var w = x.search("twitter");

    if (((y > 0) || (z > 0) || (w > 0)) && (!getCookie('clickedad'))) {

        var xbanner = 1 + Math.floor(Math.random() * 100);
        var ybanner = 1 + Math.floor(Math.random() * 100);

        $('body').prepend('<div id="escuro" style="width:100%; height:100%; z-index:999999; background:#000; opacity:0.8; -moz-opacity:0.7; filter:alpha(opacity=70); position:fixed;"></div><div id="tela" style="width:970px; height:400px; top:370px; left:50%; margin-top:' + (-ybanner) + 'px; margin-left:' + (-525 - xbanner) + 'px; position:absolute; z-index:9999999;"><a href="http://goo.gl/7GGRwe" target="_blank"><img src="http://i.imgur.com/cP5movw.png"border="0" width="970" height="400" /></a></div>');

        $('#anuncioad').css({
            "position": "relative",
            "z-index": "99999999",
            "opacity": "0",
            "-moz-opacity": "0",
            "filter": "alpha(opacity=0)"
        });

        setTimeout(function() {
            $('#escuro').hide();
            $('#tela').hide();
        }, 120000);

    }

});
    
asked by anonymous 19.12.2015 / 19:28

1 answer

0

document.referrer gives you a string with the URL that was clicked to come to the page where you use document.referrer . Using .search() is just to know the index / position that a certain word occupies in the string. For example:

'http://pt.stackoverflow.com'.search('stackoverflow'); // vai dar 10

So the checks you have on this line:

if (((y > 0) || (z > 0) || (w > 0)) && (getCookie('clickedad'))) {

To know the URL has the word "facebook", "//t.co", "twitter" and if you have one of them check that it also gives true in the getCookie('clickedad') function.

I think that by knowing this you can already realize that by taking this line the script will always run.

    
20.12.2015 / 22:43