vendredi 13 juillet 2018

javascript function always return the first element [duplicate]

This question already has an answer here:

I have the following javascript function to check a link and based on the link being a track or album, it should extract the id from the link, but it'll never go pass the first if statement, it will always alert found track in link, even though I provide a album link, any help would be appreciated. the links look like the following :

https://open.spotify.com/album/1XGo0OD90wIlRccwLe29L9?si=egthfx9CRfuPIhLJ1uXCPA
https://open.spotify.com/track/1SWyGZhn3nyLUZRfWvQ0to?si=Tl-fwsqxQf-J8gZWps2PqQ

function getLinkID(link) {
        if(link.indexOf("spotify")) {
            if(link.indexOf("track")) {
                alert("found track in link");
                var linkID = link.split('track/').pop().split('?')[0];
            } else if(link.indexOf("album")) {
                alert("found album in link");
                var linkID = link.split('album/').pop().split('?')[0];

            }
        } else if(link.indexOf("apple")) {

        } 
        return linkID;
    }

Aucun commentaire:

Enregistrer un commentaire