views:

126

answers:

2

I wrote a plug-in for jQuery that copy the the output of the ads JavaScript to there container Div.

so i put the Ads JS at the bottom of the page (so they will not decrease my page load speed) within inadvisable Divs that looks like:

<div id="ad_loader_4" class="ads_loader"></div>

the id of those divs point to the container divs. the container divs looks like:

<div id="ad_4"></div>

the jQuery plug-in waits for the page end loading and then grabs all the elements that created in the invisible divs and appends them to the container div.

The jQuery Plug-In looks like:

(function($) {  
// jQuery plugin definition  
$.fn.adsLoader = function(params) {  
    // merge default and user parameters  
    params = $.extend( {}, params);  
    // traverse all nodes  
    this.each(function() {  
        // express a single node as a jQuery object  
        var $t = $(this);  
        // find id  
        var id = $t.attr('id');
        id = id.substring(10,id.length);
        $t.children().not('script').appendTo("#ad_"+id);
    });  
    // allow jQuery chaining  
    return this;  
};  
})(jQuery);

that plug-in works great in FF and Chrome And IE8...on Adsense and some other Ads programs...but the problems begins On IE7...From some reason, sometimes the ads loads in the containers and sometimes they not...

What is wrong with my plugin?

A: 

I simplified a bit.

(function($) {
// jQuery plugin definition
$.fn.adsLoader = function() {
    // traverse all nodes
    this.each(function() {
        // get ad id and replace
        var id = this.id.substr(10);
        $("#ad_"+id).replaceWith(this);
    });
    // allow jQuery chaining
    return this;
};
})(jQuery);

NOTE: If you are hiding the bottom divs, you may need to show them after replacing the empty divs with them.

galambalazs
this will not work, because all the ads programs using document.write in there javascript, so it will write on all the page... this is why i told the plug to escape the script tag...
CaTz
A: 

someone has any suggestions?

CaTz
someone has any suggestions?
CaTz