var iframe = document.querySelector('#third-party-tracking-sandbox-iframe'); var url = "https://www.wf-box.net/sandboxed_ad_vendor_iframe.html"; iframe.addEventListener('load', function() { iframe.contentWindow.postMessage({ isAdTracking: true, trackingType: 'reddit', eventName: 'PageVisit' }, 'https://www.wf-box.net'); }); iframe.setAttribute('src', url + window.location.search);