0

We are using the Ning platform, and in order to add a new container DIV underneath the blog content (but before the comment section), we added the following before the body tag:

<script type="text/javascript">
if (typeof(x$) != 'undefined') {
x$("DIV.xg_module.xg_blog.xg_blog_detail.xg_blog_mypage.xg_module_with_dialog").after('<div>CONTENT GOES HERE </div>');
}
else{
}
</script>

However, then the content we need to load is javascript from an affiliate program, who sent us this code to add into that div:

<div style="width:750px;">
<div style="border-bottom:1px solid #FFFFFF;color:#FFFFFF;font-family:Arial,Helvetica,sans-serif;font-size:22px;font-weight:bolder;margin-bottom:10px;padding-bottom:2px;text-transform:uppercase;">From Around the Web</div>
<script type='text/javascript'>
var _CI = _CI || {};
(function() {
var script = document.createElement('script');
ref = document.getElementsByTagName('script')[0];
_CI.counter = (_CI.counter) ? _CI.counter + 1 : 1;
document.write('<div id="_CI_widget_');
document.write(_CI.counter+'"></div>');
script.type = 'text/javascript';
script.src = 'http://widget.crowdignite.com/widgets/29949?_ci_wid=_CI_widget_'+_CI.counter;
script.async = true;
ref.parentNode.insertBefore(script, ref);
})(); </script>
</div>

And obviously, that does not work.

THE QUESTION: is there a better way to do this? Is it just a matter of all the conflicting 's and "s? Is there an easier way to format this or output it? Is it failing because it's simply not loading the javascript after the JQuery has already run post-page load? I have been trying different things and none seem to work and my eyes are ready to pop out of their sockets because I know there's something stupid I'm missing, so I thought I'd get some more eyes on it.

Thanks for any help/ideas/suggestions.

  • See if you can get the script working in a simple (Ning-less) page then build up the extra functionality gradually. FYI, I tried to get the script working, but failed. – Beetroot-Beetroot Mar 21 '13 at 11:56
  • The javascript from the affiliate program is sound (it's very similar to how Facebook does their "like" widgets). I just can't seem to figure out how to load that chunk of code into the page using the top code. I'm still trying a variety of ways (like using returns, or trying to save the affiliate code as it's own .js and load it externally) and I'm just stuck. I'll keep trying. – Peter Sorensen Mar 21 '13 at 16:33

1 Answers1

0

Try appending your new script element to the head element on your page. Most dynamic script loaders do this.

See Ways to add javascript files dynamically in a page for an example.

Community
  • 1
  • 1
Rich Wagenknecht
  • 670
  • 7
  • 13