Last active
November 2, 2017 17:30
-
-
Save RobertCam/3b74c7098667f0a3ef24ca576891eb52 to your computer and use it in GitHub Desktop.
Javascript to dynamically change an embedded video based on URL params
This file contains 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
<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