Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Converting HTML links to SoundCloud widgets using JQuery
// if you have a link in your HTML that points to a sound: <a href="http://soundcloud.com/matas/hobnotropic">My Track</a>
// it will convert them to our new HTML5 widgets
$('a[href*="soundcloud.com"]').each(function(){
var $link = $(this);
$.getJSON('http://soundcloud.com/oembed?format=js&url=' + $link.attr('href') + '&iframe=true&callback=?', function(response){
$link.replaceWith(response.html);
});
});
@echteinfachtv

This comment has been minimized.

Show comment
Hide comment
@echteinfachtv

echteinfachtv May 5, 2013

wonderful, worked like a charme. Thank you very much!

wonderful, worked like a charme. Thank you very much!

@gtraxx

This comment has been minimized.

Show comment
Hide comment
@gtraxx

gtraxx Jul 2, 2013

Thank you very much! ;)

gtraxx commented Jul 2, 2013

Thank you very much! ;)

@kplates

This comment has been minimized.

Show comment
Hide comment
@kplates

kplates Sep 5, 2013

word up! very cool

kplates commented Sep 5, 2013

word up! very cool

@jrevillini

This comment has been minimized.

Show comment
Hide comment
@jrevillini

jrevillini Apr 16, 2018

This version works on HTTPS / SSL sites:

    // if you have a link in your HTML that points to a sound: <a href="http://soundcloud.com/matas/hobnotropic">My Track</a>
    // it will convert them to our new HTML5 widgets
    $('a[href*="soundcloud.com"]').each(function(){
      var $link = $(this);
      $.getJSON('//soundcloud.com/oembed?format=js&url=' + $link.attr('href') + '&iframe=true&callback=?', function(response){
        $link.replaceWith(response.html);
      });
    });

jrevillini commented Apr 16, 2018

This version works on HTTPS / SSL sites:

    // if you have a link in your HTML that points to a sound: <a href="http://soundcloud.com/matas/hobnotropic">My Track</a>
    // it will convert them to our new HTML5 widgets
    $('a[href*="soundcloud.com"]').each(function(){
      var $link = $(this);
      $.getJSON('//soundcloud.com/oembed?format=js&url=' + $link.attr('href') + '&iframe=true&callback=?', function(response){
        $link.replaceWith(response.html);
      });
    });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment