0

How do I add adsense code to this javascript code. I think there might be a solution with jquery and getscript, but I'm not able to get it to work

<script>
var rep = $("#topbar").find(".reputation-score").text().replace(/,|\s/g,'');
if (rep.match(/\d+k/i)) rep = rep.replace(/k/g, '') * 1000;
if (rep == "") rep = 0;
if (rep < 200 && $("#banner-bottom").length == 0) {
  if ($(".answer").length == 0)
    abovebanner = $("#answers-header");
  else
    abovebanner = $(".answer:first");
  abovebanner.after('HELP ADD ADSENSE CODE HERE');
}
</script>

and guys I'm not very good with javascript, so if you guys could paste a working solution. I'd really appreciate it.

1 Answer 1

2

This page explains a method to do this. Once you have created the wrapper function (addJavascript) mentioned on that page added, your last line would like something like:

addJavascript('adsense-library-name.js','head');

The implementation of addJavascript (from the page above):

function addJavascript(jsname,pos) {
  var th = document.getElementsByTagName(pos)[0];
  var s = document.createElement('script');
  s.setAttribute('type','text/javascript');
  s.setAttribute('src',jsname);
  th.appendChild(s);
}
Sign up to request clarification or add additional context in comments.

2 Comments

Please provide an answer here, in part at the very least.
@Jonathan Sampson: Who do you mean, the OP?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.