How does the site know what sites you are logged into? Is there some sort of guesswork involved?
Javascript in one site can't just access another website's content. That's the Same Origin Policy. But what you can do is dynamically link to an image on another website. You can't access its content, but you can know if it loaded correctly. So if you find some image that is only accessible to a logged-in user (non logged-in gets a redirect for example) you can determine logged in status.
Another technique uses time measurements and non-image resources. Loading them as an image will fail anyway, but if there is a substantial time difference in the error response for logged-in vs not, it can be done that way too.