A
A
Alexey Krylov2015-10-06 17:24:53
JavaScript
Alexey Krylov, 2015-10-06 17:24:53

How to run a script with the condition that the page was visited from another site?

There is a script

<script>
   $(document).ready(function() {
        if (YMaps.location.city != '') {
            var youRegion = (YMaps.location.city);
            if (youRegion === "Екатеринбург"){
                setTimeout(function(){(Image ? (new Image()) : document.createElement('img')).src = location.protocol + '//vk.com/rtrg?r=ecPI*kK4/oqgC0i5tI5rhw6KUcrjXxV7JlAoaLB2cMqJrcyvMXi9YSqeN2Y/RFBz925QNz1suYZKQ8QiO0uMEeM25hZlfhvhuUkU7C6kVD/Hkv11/ouv48EfbJdKJ2nPeo51wIdPMyy2j6d9DEtA63*PjszmFjfZNucc94G6TRY-';}, 19000);
 setTimeout(function(){_tmr.push({ id: "2692689", type: "reachGoal", goal: "test" });}, 19000);}
            else{}
        }
    });
</script>

One more trigger condition needs to be added. So that it runs under the conditions that the page (where the script is located) was visited from any other site, and did not follow internal links. As I understand it, you need to use document.referrer.
But I'm not a scripting expert. I will be very grateful for your help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Inchin ☢, 2015-10-06
@Telos

document.referrercontains the address from which the transition to the current page was made. Check it for a mismatch with the current domain and do what you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question