Skip to content

Instantly share code, notes, and snippets.

@RobertCam
Last active November 2, 2017 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobertCam/3b74c7098667f0a3ef24ca576891eb52 to your computer and use it in GitHub Desktop.
Save RobertCam/3b74c7098667f0a3ef24ca576891eb52 to your computer and use it in GitHub Desktop.
Javascript to dynamically change an embedded video based on URL params
<script>
/*
Unbounce Community :: Tips & Scripts :: Dynamically Swap an Embedded Video with URL Parameters
TS:0002-04-047
***********************
Do not remove this section. It helps our team track useage of external workarounds.
*/
function getURLParameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null
}
var src = getURLParameter('src');
if (src) {
var html = '<iframe id="video" width="100%" height="315px" src='+src+' frameborder="0" allowfullscreen=""></iframe>'; // Add the preferred dimensions of the video
document.getElementById('vid-container').innerHTML = html;
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment