Add time to a JS iframe

Asked

Viewed 87 times

0

Hello, I’m developing a system and I need Javascript to add the time between the end of the page load and the click on the content of the iframe. I tried to use the code below, var myInterval, but in iframe it is only '1', that is, it does not update with the passing of seconds. After the page loaded by what looks like the team ('&t=' + myInterval + ') gets the static number 1.

if(!window.alreadyIncluded) {
    var t = 0;

    var time = 0;
    var myInterval = setInterval(function() {
        ++time;
    }, 1000);

    var divList = document.getElementsByClassName('network');
    for (var i = divList.length - 1; i >= 0; i--) {
        t++;

        var rf = document.referrer;
        var lh = window.location.host;

        var slot = divList[i].getAttribute('data-ad-s');
        var client = divList[i].getAttribute('data-ad-c');
        var width = divList[i].offsetWidth;
        var height = divList[i].offsetHeight;

        divList[i].innerHTML = ('<iframe id="ad_iframe_' + t + '" name="ad_iframe_' + t + '" width="' + width + '" height="' + height + '" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" src="<?php echo $site->getSiteURL(); ?>/page/generate.php?s=' + slot + '&c=' + client + '&lh=' + lh + '&rf=' + rf + '&t=' + myInterval + '"></iframe>');
    }
    window.alreadyIncluded = true;
}

I’ve tried several ways to make myInterval keep updating every second even after the full page load, but not it remains static at 1, any idea?

  • 1

    Buddy, the loop takes place in here var myInterval = setInterval(function() {&#xA; ++time;&#xA; }, 1000); the rest will not repeat itself

  • And how could I get myInterval to keep counting?

  • The added value in the loop is the var time the myInterval no value is just a reference, actually I didn’t quite understand what you want to do.. It’s counting, variable time is updated every second

  • What I want is that when someone click on the content of the iframe, php give get in the amount of seconds that passed between the loading of the JS and the visitor click, understand? When I put ' + time + ' instead of myInterval $_GET[’t'] returns 0. (I’m using die($_GET[’t']) to check this).

No answers

Browser other questions tagged

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