Skip to content

Instantly share code, notes, and snippets.

@craigmdennis
Created February 6, 2012 20:35
Show Gist options
  • Save craigmdennis/1754660 to your computer and use it in GitHub Desktop.
Save craigmdennis/1754660 to your computer and use it in GitHub Desktop.
Add wmode=transparent to YouTube iframes
function wmode() {
// For each iFrame
$('iframe').each(function () {
// Store some variables
var $this = $(this),
src = $this.attr('src'),
query;
// If the src does not contain 'youtube'
if (src.indexOf('youtube') > -1) {
// exit the function
return false;
// Otherwise it does so do more stuff
} else {
// If it already has wmode=transparent
if (src.indexOf('wmode=transparent') > -1) {
// If the src contains a ?
if (src.indexOf('?') > -1) {
// Set the query to a & (as it's another parameter)
query = '&';
} else {
// Else set the query to ? (as the src currently has 0 parameters)
query = '?';
}
// Add the string to the iFrame src
$this.attr('src', src + query + 'wmode=transparent');
}
}
});
}
// Call the function
wmode();
@craigmdennis
Copy link
Author

Not sure whether to check if it's a youtube iframe or if it has wmode=transparent first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment