Skip to content

Instantly share code, notes, and snippets.

@mataspetrikas
Created February 2, 2012 14:24
Show Gist options
  • Save mataspetrikas/1723694 to your computer and use it in GitHub Desktop.
Save mataspetrikas/1723694 to your computer and use it in GitHub Desktop.
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);
});
});
@jrevillini
Copy link

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