I'm trying to asynchronously (or lazy load) this Reddit widget, but I'm having an issue.
Here's the basic code that works perfectly when directly in the html:
<script src="http://www.reddit.com/domain/skattertech.com/new/.embed?limit=4&t=all&sort=new&style=off" type="text/javascript"></script>
If I try to move that over into my scripts.js where I execute other jQuery stuff, it ends up rewriting the entire DOM with the widget. I'm aware that loading that src in the browser shows the code that's being executed begins with document.write. So I'm guessing since it's loosing a reference point, it's overwriting the entire window.
Here are the two methods I had attempted and failed:
$('.redditdiv').html('<script src="http://www.reddit.com/domain/skattertech.com/new/.embed?limit=4&t=all&sort=new&style=off" type="text/javascript"></script>');
The other failed attempt:
var redditscript = document.createElement('SCRIPT');
redditscript.type = 'text/javascript';
redditscript.async = true;
redditscript.src = 'http://www.reddit.com/domain/skattertech.com/new/.embed?limit=4&t=all&sort=new&style=off';
$('.redditdiv').append(redditscript);
If anyone has a suggestion, that would be quite awesome. Thanks!
P.S. Bonus Question: Does anyone have a suggestion for this Twitter Widget too?
<script src="http://widgets.twimg.com/j/2/widget.js"></script>
<script>
new TWTR.Widget({version: 2,type: 'profile',rpp: 4,interval: 6000,width: 'auto',height: 300, theme: {shell: {background: '#ffffff',color: '#000000'},tweets: {background: '#ffffff',color: '#606060',links: '#4476cc'} }, features: {scrollbar: false,loop: false,live: false,hashtags: false,timestamp: true,avatars: false,behavior: 'all'} }).render().setUser('skattertech').start();
</script>