Created
May 1, 2015 07:45
-
-
Save ericls/1f365b34b18abd9f0792 to your computer and use it in GitHub Desktop.
replace youtube url with embeded video
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> | |
<head> | |
<meta charset="utf-8" /> | |
<title></title> | |
<link rel="stylesheet" href="style.css" /> | |
<script data-require="jquery" data-semver="2.1.3" src="http://code.jquery.com/jquery-2.1.3.min.js"></script> | |
<script src="script.js"></script> | |
</head> | |
<body> | |
<a href="https://youtu.be/Rr9i16FDl9E" target="_blank">视频</a> | |
<a href="https://www.youtube.com/watch?v=Rr9i16FDl9E" target="_blank">视频2</a> | |
<script> | |
$(document).ready( | |
function() { | |
$('a').each(function(i, e) { | |
url = e.attributes['href'].value; | |
if (url.indexOf('youtu.be') != -1) { | |
video_id = url.split('/')[3]; | |
$(e).replaceWith('<iframe width="100%" height="360" src=" https://www.youtube.com/embed/' + video_id + '" frameborder="0" allowfullscreen></iframe>') | |
} else if (url.indexOf('www.youtube.com/watch') != -1) { | |
video_id = url.split('=')[1]; | |
$(e).replaceWith('<iframe width="100%" height="360" src=" https://www.youtube.com/embed/' + video_id + '" frameborder="0" allowfullscreen></iframe>') | |
} | |
}); | |
} | |
) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment