我在我的网站上使用了2个弹出广告标记,因此为了不打扰访问者,我希望在第一次弹出和第二次弹出之间通过javascript或jquery制作延迟时间。
例如
第一个标签将在完整页面加载后60秒后执行或加载,第二个弹出窗口将在20分钟后加载
TAG 1:
<script type="text/javascript">
var ad_id = 111111;
var ad_advert = 'int';
var frequency_cap = 5;
var frequency_delay = 5;
var init_delay = 3;
var popunder = true;
</script>
<script src="https://cdn.popup.pop/js/entry.js"></script>
TAG 2:
<script type="text/javascript">
var ad_id = 22222;
var ad_advert = 'int';
var frequency_cap = 5;
var frequency_delay = 5;
var init_delay = 3;
var popunder = true;
</script>
<script src="https://cdn.upup.up/js/entry.js"></script>
此致
更新:仍然无效,请解决任何问题
<script type="text/javascript">
var adfly_id = 17609785;
var adfly_advert = 'int';
var frequency_cap = 1000;
var frequency_delay = 0;
var init_delay = 0;
var popunder = true;
</script>
<script type="text/javascript">
function injectJs(url) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.async = true;
script.onload = function(){
// remote script has loaded
};
script.src = url;
document.getElementsByTagName('head')[0].appendChild(script);
}
(function() {
setTimeout(function(){ injectJs('https://cdn.adf.ly/js/entry.js')}, 1000 * 3); // 3 seconds or
setTimeout(function(){ injectJs('https://cdn.adf.ly/js/entry.js')}, 1000 * 60 * 20); //20 min
})()
</script>
答案 0 :(得分:0)
您可以使用settimeout函数使用此链接inject a script tag with remote src and wait for it to execute加载js文件。
function injectJs(url) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.async = true;
script.onload = function(){
// remote script has loaded
};
script.src = url;
document.getElementsByTagName('head')[0].appendChild(script);
}
(function() {
setTimeout(function(){ injectJs('https://cdn.popup.pop/js/entry.js')}, 1000 * 60); // 60 seconds or 1 min
setTimeout(function(){ injectJs('https://cdn.upup.up/js/entry.js')}, 1000 * 60 * 20); //20 min
})()
答案 1 :(得分:0)
$(window).on('load',function(){
setTimeout(function(){ ///excute first popup
console.log('first Excute!')
},10000);
})
$(function(){
setTimeout(function(){ ///excute second popup
console.log('second Excute!')
},200000);
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
&#13;
尝试这个。