In this thread @TheBronx wrote about getting around the document.write
issue: Re: NodeBB and ads - A never ending story
My site wasn't approved for AdSense (or DFP) due to a lack of volume. I am working on building site activity but in the meantime I have signed up with Chitika for publishing ads. Chitika uses document.write
and I would really like to get their code bit working with the little trick that TheBronx devised.
Would someone be willing to help me re-write this code block to work as he outlined?
This is what he posted:
Here is some code:
var originalFunction = document.write;
overrideDocumentWriteFunction = function(container) {
document.write = function(content) {
container.innerHTML = content;
document.write = originalFunction;
};
};
And I used it like this:
var div = document.getElementById('adPlacement');
overrideDocumentWriteFunction(div);
var script = document.createElement('script');
script.type = 'text/javascript';
script.innerHTML = '{adsense script content}'
document.body.appendChild(script);
This way the document.write function was customized to ensure the Adsense script worked after the page was loaded.
This is the Chitika ad code:
<script type="text/javascript">
( function() {
if (window.CHITIKA === undefined) { window.CHITIKA = { 'units' : [] }; };
var unit = {"calltype":"async[2]","publisher":"myPublisherId","width":728,"height":90,"sid":"Chitika Default"};
var placement_id = window.CHITIKA.units.length;
window.CHITIKA.units.push(unit);
document.write('<div id="chitikaAdBlock-' + placement_id + '"></div>');
}());
</script>
<script type="text/javascript" src="//cdn.chitika.net/getads.js" async></script>
If anyone would like to lend a hand in re-packaging their code with the proposal that TheBronx made I would be very grateful and appreciative.
Thank you.