Skip to content

Instantly share code, notes, and snippets.

@stellarcowboy
Created February 11, 2012 16:59
Show Gist options
  • Save stellarcowboy/1802252 to your computer and use it in GitHub Desktop.
Save stellarcowboy/1802252 to your computer and use it in GitHub Desktop.
Conditionally load Facebook social plugin based on screen width
<div id="fb-catcher"></div>
<script>
if (document.documentElement.clientWidth >= 600) {
document.getElementById('fb-catcher').innerHTML='<div id="fb-root"></div>';
}
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=xxxxxxxxxxxxx";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment