Created
February 6, 2012 20:35
-
-
Save craigmdennis/1754660 to your computer and use it in GitHub Desktop.
Add wmode=transparent to YouTube iframes
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
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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not sure whether to check if it's a youtube iframe or if it has wmode=transparent first.