Skip to content

Instantly share code, notes, and snippets.

@ryu-blacknd
Created August 1, 2012 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryu-blacknd/3229930 to your computer and use it in GitHub Desktop.
Save ryu-blacknd/3229930 to your computer and use it in GitHub Desktop.
非同期でソーシャルボタンの.jsを読み込むサンプル
<script type="text/javascript">
( function( doc, script ) {
    var js;
    var fjs = doc.getElementsByTagName( script )[0];
    var add = function( url, id, o ) {
        if ( doc.getElementById( id ) ) { return; }
        js = doc.createElement( script );
        js.src = url; js.async = true; js.id = id;
        fjs.parentNode.insertBefore( js, fjs );
        if ( window.ActiveXObject && o != null ) {
            js.onreadystatechange = function() {
                if ( js.readyState == 'complete' ) o();
                if ( js.readyState == 'loaded' ) o();
            };
        } else {
            js.onload = o;
        }
    };
    // Google+1
    window.___gcfg = { lang: "ja" };
    add( '<a href="https://apis.google.com/js/plusone.js" target="_blank" rel="noreferrer" style="cursor:help;display:inline !important;">https://apis.google.com/js/plusone.js</a>' );
    // Facebook
    add( '//connect.facebook.net/ja_JP/all.js', 'facebook-jssdk', function() {
        add( '<a href="http://static.ak.fbcdn.net/connect.php/js/FB.Share" target="_blank" rel="noreferrer" style="cursor:help;display:inline !important;">http://static.ak.fbcdn.net/connect.php/js/FB.Share</a>', 'facebook-share' );
    });
    // Twitter
    add( '//platform.twitter.com/widgets.js', 'twitter-wjs' );
    // はてな
    add( '<a href="http://b.st-hatena.com/js/bookmark_button.js" target="_blank" rel="noreferrer" style="cursor:help;display:inline !important;">http://b.st-hatena.com/js/bookmark_button.js</a>', 'hatena-js' );
}( document, 'script' ) );
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment