Prevent song playing on URI link click

2019-08-19 07:11发布

问题:

I'm working on a Spotify app where I'd like for users to be able to click on track names and be linked to the track page, just like in other Spotify apps. I'd like to prevent the song from beginning playback, though.

SoundDrop seems to do this. You can click on a track name and the song doesn't interrupt playback by SoundDrop.

I'm not sure how to implement this alternative behavior. Any ideas?

回答1:

The Apps API uses standard JavaScript stuff, so if you attach a handler to the track link and use e.preventDefault(), that should prevent Spotify playing the track and you can then do your own custom handling.

More discussion on e.preventDefault() is here: event.preventDefault() vs. return false



标签: spotify