One way of detecting a spotify installation: Spotify runs an http server (1234.spotilocal.com:12345 -> 127.0.0.1:12345
) on the client computer if you have spotify installed, to enable javascript interaction. To detect if spotify is installed, try to connect to the local server to see if it exists. However, this does not guarantee that spotify:
links will work as it may be disabled by the user, but it's a lot easier than detecting a custom protocol handler. Finally, you might run into cross-domain issues, I'm not sure if the local server supports JSONP... If you want to go down this long road, here's a good read.
To stay simple still get a clean fallback, consider using http://open.spotify.com/track/(yourTrackNo) urls instead. The open.spotify.com page will detect if spotify is installed and prompt the user to install and/or listen online if its not. To get the url (yourTrackNo)
of your song if you don't already have it (i don't know how you generate your links, manually?), you have to use the Spotify Metadata Api, now deprecated in favour of Spotify WebApi