Created
January 18, 2018 15:09
-
-
Save sethbergman/c9c23bc777580a9b0a98cdf1016dbdf9 to your computer and use it in GitHub Desktop.
Vimeo oembed sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Vimeo Javascript oEmbed Example</title> | |
<script> | |
// This is the URL of the video you want to load | |
var videoUrl = 'http://www.vimeo.com/7100569'; | |
// This is the oEmbed endpoint for Vimeo (we're using JSON) | |
// (Vimeo also supports oEmbed discovery. See the PHP example.) | |
var endpoint = 'http://www.vimeo.com/api/oembed.json'; | |
// Tell Vimeo what function to call | |
var callback = 'embedVideo'; | |
// Put together the URL | |
var url = endpoint + '?url=' + encodeURIComponent(videoUrl) + '&callback=' + callback + '&width=640'; | |
// This function puts the video on the page | |
function embedVideo(video) { | |
document.getElementById('embed').innerHTML = unescape(video.html); | |
} | |
// This function loads the data from Vimeo | |
function init() { | |
var js = document.createElement('script'); | |
js.setAttribute('type', 'text/javascript'); | |
js.setAttribute('src', url); | |
document.getElementsByTagName('head').item(0).appendChild(js); | |
} | |
// Call our init function when the page loads | |
window.onload = init; | |
</script> | |
</head> | |
<body> | |
<h1>Vimeo Javascript oEmbed Example</h1> | |
<div id="embed">Loading video...</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment