How do I get referrer from this script? I want it to open when I come from any site

Asked

Viewed 138 times

-4

Hello. I have a script, but it only opens when it comes from certain websites. How do I make it always open without having to referrer and keep cookies? Thank you 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);

    }

});

1 answer

0

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

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

So the checks you have on this line:

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

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

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

  • I pulled the whole line out and it didn’t work.. :(

  • Only part of it was to be taken away?

  • @Hugoleonardo you removed the whole line and it didn’t work? gave some error?

  • No error, but the script did not open

Browser other questions tagged

You are not signed in. Login or sign up in order to post.