Javascript call after dom completes

We use an external system to serve ads on our site. Currently, in our header files, we have js that uses jquery to insert data into our ad holder, which is a div that appears on every page, i.e.

$("#adSpot").prepend('put my ad here');

      

Our third party ad system just started using Google Ad Server another system to serve ads, so now we have provided us with a JS to call. I would like to use our header files and do not have to touch every file, but I am unable to insert the js which is then executed like this:

$("#adSpot").prepend('GA_googleFillSlotWithSize("ca-pub-981", "Page_1", 468, 60)');

      

Basically, I would like to use a header file, so when the page loads, it injects this js code into the div where we want the image to be positioned, and then js is executed to make the image appear in the spot. Now it is pushing the code to the div but the js is not executed.

Thank!

+2


source to share


4 answers


In your header.php replace the line $("#adSpot).prepend()

with this code:

var adCode=GA_googleFillSlotWithSize("ca-pub-981", "Page_1", 468, 60);
$("#adSpot").prepend(adCode);

      



What do you get when you try this code?

+3


source


Don't understand why you are doing this, but seeing that you insist on putting JavaScript in a div, have you tried wrapping it in a script tag and adding it to a div?



$("#adSpot").prepend('<script type="text/javascript">GA_googleFillSlotWithSize("ca-pub-981", "Page_1", 468, 60)</script>');

      

+1


source


Since it looks like you are already using jquery:

$(document).ready(function() {
    //dom is ready
});

// alternatively:
$(function() { 
    // dom is ready
});

      

Both are the same, the second is just a shorter notation for the first.

0


source


$(document).ready(function(){
  // Your code here...
});

      

Source

0


source







All Articles