Jump to content

delete-me

Approved members
  • Posts

    2
  • Joined

  • Last visited

About delete-me

delete-me's Achievements

Newbie

Newbie (1/5)

1

Reputation

  1. The last two lines of javascript got truncated in my post (I've gone back and corrected it). Here is a complete example: <!DOCTYPE html> <html> <head> <script src="/path/to/element.write.js"></script> <script src="/path/to/writeCapture2.js"></script> <title>Async Ad Test</title> </head> <body> <div id="AdPlaceholder"> <!-- ad will go here --> </div> <script> /* this function wrapper keeps global memory space clear of random variables */ (function(){ writeCapture.write( document.getElementById("AdPlaceholder"), '<scr' + 'ipt>' + 'var oxSrc = (document.location.protocol === "https:" ? "https:" : "http:")' + '+ "//example.com/ReviveAdServer/www/delivery/ajs.php"' + '+ "?zoneid=123&block=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=\'" + oxSrc + "\'></scr" + "ipt>");' + '</scr' + 'ipt>' ); })(); </script> </body> </html> Here is a simple real-world working example: http://constructionjobs.com/test.php
  2. Since I've taken the time to find a solution which works for my website, I decided to pass along my solution. This works in a jQuery environment, but doesn't depend on jQuery. Using this Javascript library (available under the terms of the MIT License): https://github.com/iamnoah/writeCapture/tree/writeCapture2 First, load the library, so you can use the function: <script src="/path/to/element.write.js"></script> <script src="/path/to/writeCapture2.js"></script> Then simply rewrite your invocation code like so <div id="AdPlaceholder"> <!-- ad will go here --> </div> <script> /* this function wrapper keeps global memory space clear of random variables */ (function(){ var oxSrc = (document.location.protocol === "https:" ? "https:" : "http:") + "//example.com/ReviveAdserver/www/delivery/ajs.php" + "?zoneid=123&block=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" : ""); writeCapture.write( document.getElementById("AdPlaceholder"), "<scr" + "ipt src='" + oxSrc + "'></scr" + "ipt>" ); })(); </script> If you don't need the ability to prevent displaying the same banner / campaign / advertiser on a single page, then you are done. If your like me, and need campaign and advertiser blocking (to prevent duplicates), you'll have to do continue with the next step. When the javascript runs the string stored in oxSrc has the current value of document.context, however subsequent ads need the revised value of document.context, to prevent duplicate ads. The solution is to wrap the string creation into the javascript which is excuted asynchronously, so that the revised value of document.context is used, like so <div id="AdPlaceholder"> <!-- ad will go here --> </div> <script> /* this function wrapper keeps global memory space clear of random variables */ (function(){ writeCapture.write( document.getElementById("AdPlaceholder"), '<scr' + 'ipt>' + 'var oxSrc = (document.location.protocol === "https:" ? "https:" : "http:")' + '+ "//example.com/ReviveAdserver/www/delivery/ajs.php"' + '+ "?zoneid=123&block=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=\'" + oxSrc + "\'></scr" + "ipt>");' + '</scr' + 'ipt>' ); })(); </script> Yes, this is quite ugly code, and you'll have to be careful when editing it, as it's javascript which writes javascript. I hope this is able to help people, until Revive Adserver offers a direct solution to display ads asynchronously.
×
×
  • Create New...