Skip to main content
100%

On Surftourist.com we've had some people putting in a vimeo or youtube link in their descriptions. We want to support video properly, but this is a quick attempt at addressing the solution for the meantime.

✓ Published0🌍 Public
DDylanFM
Last edited Jun 9, 2011
Created on Jun 9, 2011

This example shows how user-submitted descriptions on Surftourist.com can automatically detect YouTube and Vimeo links and replace them with embedded video players. The code searches an element’s HTML for matching URLs using a regular expression, then for each match it queries either Vimeo’s oEmbed API or Embedly’s oEmbed endpoint (for YouTube) via JSONP, and finally swaps the original link with the returned HTML embed code. The rendering approach relies on jQuery’s `$.ajax` for cross-domain requests, with a maximum embed height of 300 pixels.

AI-generated description

Similar vizzes