Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save johnbacon/4430125 to your computer and use it in GitHub Desktop.
Save johnbacon/4430125 to your computer and use it in GitHub Desktop.
(function() {
var url = '//connect.facebook.net/en_US/all.js';
var iframe = document.createElement('iframe');
(iframe.frameElement || iframe).style.cssText = "width: 0; height: 0; border: 0";
iframe.src = "javascript:false";
document.getElementById('fb-root').appendChild(iframe);
var doc = iframe.contentWindow.document;
doc.open().write('<body onload="'+
'window.inDapIF = true;' +
'var js = document.createElement(\'script\');'+
'js.src = \''+ url +'\';'+
'document.body.appendChild(js);">');
doc.close();
}());
// async init once loading is done
window.fbAsyncInit = function() {
FB.init({xfbml: true});
};
(function(url){
// Section 1
var iframe = document.createElement('iframe');
iframe.src = "javascript:false";
(iframe.frameElement || iframe).style.cssText = "width: 0; height: 0; border: 0";
var where = document.getElementsByTagName('script');
where = where[where.length - 1];
where.parentNode.insertBefore(iframe, where);
// Section 2
var doc = iframe.contentWindow.document;
doc.open().write('<body onload="'+
'var js = document.createElement(\'script\');'+
'js.id = \'js-iframe-async\';'+
'js.src = \''+ url +'\';'+
'document.body.appendChild(js);">');
doc.close();
})('http://some.site.com/script.js');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment