Reputation: 110
I'm using Revive Ad Server, and I moved the Invocation Code for my ads in divs below my footer, and then used jQuery to append them to where they're supposed to load. How can I delay the loading of the ads so they rest of my scripts can load? For example, I'm using Nivo Slider (which is loaded in head), but the first image won't display until all the ad scripts have loaded, which takes a couple seconds.
HTML with Invocation Code:
<div class="hidden">
<div id="leaderboard">
<script type='text/javascript'><!--//<![CDATA[
var m3_u = (location.protocol=='https:'?'https://www.website.com/adserver/www/delivery/ajs.php':'http://www.website.com/adserver/www/delivery/ajs.php');
var m3_r = Math.floor(Math.random()*99999999999);
if (!document.MAX_used) document.MAX_used = ',';
document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
document.write ("?zoneid=1&blockcampaign=1");
document.write ('&cb=' + m3_r);
if (document.MAX_used != ',') document.write ("&exclude=" + document.MAX_used);
document.write (document.charset ? '&charset='+document.charset : (document.characterSet ? '&charset='+document.characterSet : ''));
document.write ("&loc=" + escape(window.location));
if (document.referrer) document.write ("&referer=" + escape(document.referrer));
if (document.context) document.write ("&context=" + escape(document.context));
if (document.mmm_fo) document.write ("&mmm_fo=1");
document.write ("'><\/scr"+"ipt>");
//]]>--></script><noscript><a href='http://www.website.com/adserver/www/delivery/ck.php?n=a2ce62fe&cb=INSERT_RANDOM_NUMBER_HERE' target='_blank'><img src='http://www.website.com/adserver/www/delivery/avw.php?zoneid=1&cb=INSERT_RANDOM_NUMBER_HERE&n=a2ce62fe' border='0' alt='' /></a></noscript>
</div>
<div id="wide-skyscraper">
<script type='text/javascript'><!--//<![CDATA[
var m3_u = (location.protocol=='https:'?'https://www.website.com/adserver/www/delivery/ajs.php':'http://www.website.com/adserver/www/delivery/ajs.php');
var m3_r = Math.floor(Math.random()*99999999999);
if (!document.MAX_used) document.MAX_used = ',';
document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
document.write ("?zoneid=2&blockcampaign=1");
document.write ('&cb=' + m3_r);
if (document.MAX_used != ',') document.write ("&exclude=" + document.MAX_used);
document.write (document.charset ? '&charset='+document.charset : (document.characterSet ? '&charset='+document.characterSet : ''));
document.write ("&loc=" + escape(window.location));
if (document.referrer) document.write ("&referer=" + escape(document.referrer));
if (document.context) document.write ("&context=" + escape(document.context));
if (document.mmm_fo) document.write ("&mmm_fo=1");
document.write ("'><\/scr"+"ipt>");
//]]>--></script><noscript><a href='http://www.website.com/adserver/www/delivery/ck.php?n=a16afa56&cb=INSERT_RANDOM_NUMBER_HERE' target='_blank'><img src='http://www.website.com/adserver/www/delivery/avw.php?zoneid=2&cb=INSERT_RANDOM_NUMBER_HERE&n=a16afa56' border='0' alt='' /></a></noscript>
</div>
</div>
jQuery:
$(document).ready(function () {
// Nivo Slider code
});
$(window).load(function() {
$('#leaderboard').contents().appendTo($('.leaderboard'));
$('#wide-skyscraper').contents().appendTo($('.wide-skyscraper'));
});
Upvotes: 1
Views: 1576
Reputation: 110
Scripts
element.write.js
writeCapture2.js
JavaScript
$(document).ready(function () {
$.getScript('/assets/js/plugins/writeCapture.js', function() {
if ($('#leaderboard-1').length) {
writeCapture.write(
document.getElementById('leaderboard-1'),
'<scr' + 'ipt>' +
'var revSrc = (document.location.protocol === "https:" ? "https:" : "http:")' +
'+ "//www.website.com/adserver/www/delivery/ajs.php"' +
'+ "?zoneid=1&blockcampaign=1&cb=" + Math.floor(Math.random()*99999999999)' +
'+ "&charset=UTF-8&loc=" + encodeURIComponent(window.location)' +
'+ (document.MAX_used !== "," ? ("&exclude=" + document.MAX_used) : "")' +
'+ (document.referrer ? ("&referer=" + encodeURIComponent(document.referrer)) : "")' +
'+ (document.context ? ("&context=" + encodeURIComponent(document.context)) : "")' +
'+ (document.mmm_fo ? "&mmm_fo=1" : "");' +
'document.write("<scr" + "ipt src=\'" + revSrc + "\'></scr" + "ipt>");' +
'</scr' + 'ipt>'
);
}
if ($('#wide-skyscraper-1').length) {
writeCapture.write(
document.getElementById('wide-skyscraper-1'),
'<scr' + 'ipt>' +
'var revSrc = (document.location.protocol === "https:" ? "https:" : "http:")' +
'+ "//www.website.com/adserver/www/delivery/ajs.php"' +
'+ "?zoneid=2&blockcampaign=1&cb=" + Math.floor(Math.random()*99999999999)' +
'+ "&charset=UTF-8&loc=" + encodeURIComponent(window.location)' +
'+ (document.MAX_used !== "," ? ("&exclude=" + document.MAX_used) : "")' +
'+ (document.referrer ? ("&referer=" + encodeURIComponent(document.referrer)) : "")' +
'+ (document.context ? ("&context=" + encodeURIComponent(document.context)) : "")' +
'+ (document.mmm_fo ? "&mmm_fo=1" : "");' +
'document.write("<scr" + "ipt src=\'" + revSrc + "\'></scr" + "ipt>");' +
'</scr' + 'ipt>'
);
}
});
});
Upvotes: 0
Reputation: 10924
I can't speak towards your ToS but I think this would be possible by dynamically creating the ad script after your slider loads instead of hardcoded in the HTML. The ad site may be able to check against this and if they do, it won't work; however I would try the following:
HTML
<div class="leaderboard">
<noscript><a href='http://www.website.com/adserver/www/delivery/ck.php?n=a2ce62fe&cb=INSERT_RANDOM_NUMBER_HERE' target='_blank'><img src='http://www.website.com/adserver/www/delivery/avw.php?zoneid=1&cb=INSERT_RANDOM_NUMBER_HERE&n=a2ce62fe' border='0' alt='' /></a></noscript>
</div>
<div class="wide-skyscraper">
<noscript><a href='http://www.website.com/adserver/www/delivery/ck.php?n=a16afa56&cb=INSERT_RANDOM_NUMBER_HERE' target='_blank'><img src='http://www.website.com/adserver/www/delivery/avw.php?zoneid=2&cb=INSERT_RANDOM_NUMBER_HERE&n=a16afa56' border='0' alt='' /></a></noscript>
</div>
JavaScript
function doAds() {
getAd('a2ce62fe', 1, '.leaderboard');
getAd('a16afa56', 2, '.wide-skyscraper');
}
function getAd(n, zoneid, target) {
var adScript = "<script type='text/javascript'><!-" + "-//<![CDATA[\n";
adScript += "var m3_u = (location.protocol=='https:'?'https://www.website.com/adserver/www/delivery/ajs.php':'http://www.website.com/adserver/www/delivery/ajs.php');\n";
adScript += "var m3_r = Math.floor(Math.random()*99999999999);\n"
adScript += "if (!document.MAX_used) document.MAX_used = ',';\n";
adScript += "document.write (\"<scr\"+\"ipt type='text/javascript' src='\"+m3_u);\n";
adScript += "document.write (\"?zoneid=" + zoneid + "&blockcampaign=1\");\n";
adScript += "document.write ('&cb=' + m3_r);\n"
adScript += "if (document.MAX_used != ',') document.write (\"&exclude=\" + document.MAX_used);\n";
adScript += "document.write (document.charset ? '&charset='+document.charset : (document.characterSet ? '&charset='+document.characterSet : ''));\n";
adScript += "document.write (\"&loc=\" + escape(window.location));\n"
adScript += "if (document.referrer) document.write (\"&referer=\" + escape(document.referrer));\n";
adScript += "if (document.context) document.write (\"&context=\" + escape(document.context));\n";
adScript += "if (document.mmm_fo) document.write (\"&mmm_fo=1\"); document.write (\"'><\/scr\"+\"ipt>\");\n//]]>-" + "-></scr" + "ipt>";
$(target).prepend(adScript);
}
$(document).ready(function() {
// Nivo Slider code
$('#slider').nivoSlider({
afterLoad: function(){
doAds();
}
});
});
Upvotes: 2