don't clobber an existing onYouTubeIframeAPIReady callback
See original GitHub issue@feross great module! Love the simplicity of it.
The only issue I see right now is related to my particular use case: My code runs as a 3rd party library in someone else’s website. It’s possible that the hosting site already has a onYouTubeIframeAPIReady
function declared. Would you be open to a PR which does something like this?
if (typeof window.onYouTubeIframeAPIReady !== 'function') {
window.onYouTubeIframeAPIReady = () => {
while (loadIframeAPICallbacks.length) {
const loadCb = loadIframeAPICallbacks.shift()
loadCb(null, window.YT)
}
}
} else {
const previous = window.onYouTubeIframeAPIReady
window.onYouTubeIframeAPIReady = () => {
if (previous) {
previous()
}
loadCb(null, window.YT)
}
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
YouTube IFrame API with existing IFrame failing to run callbacks
Best way to load a Youtube Video by his API, is following this sintaxis: <div id="video-youtube"></div> <script ...
Read more >YouTube Player API Reference for iframe Embeds
The IFrame player API lets you embed a YouTube video player on your website and control the player using JavaScript. Using the API's...
Read more >gajus/youtube-player: YouTube iframe API abstraction. - GitHub
The downsides of using YouTube IFrame Player API are: Requires to define callbacks in the global scope ( window ). Requires to track...
Read more >Getting going with the YouTube API | by richard bultitude
I do this within the onYouTubeIframeAPIReady callback so it only happens when the API is definitely ready. var YT;window.onYouTubeIframeAPIReady = function() {
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This was released in 3.5.0
@feross let me know if you have any issues etc., happy to modify the PR as needed.