Detect when vimeo api is available?
Asked Answered
V

0

7

I wish to load the Vimeo player API asynchronously, using something like:

var tag = document.createElement('script')
tag.src = 'https://player.vimeo.com/api/player.js'
var firstScriptTag = document.getElementsByTagName('script')[0]
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag)

This works fine, though the side effect is that I now need a mechanism to determine when the API has loaded, to initialize a player accordingly. I could use a setInterval() to poll and detect when the Vimeo variable is available I guess, though I was hoping for a more elegant, events based approach, something like:

Vimeo.on('loaded', function(){
    new Vimeo.Player('myplayer')
})

Any ideas?

Volcano answered 14/9, 2016 at 1:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.