Say I have a website called a.com, and when a specific page of this site is loaded, say page link, I like to set a cookie for another site called b.com
Probaly you can use Iframe for this. Facebook probably uses this technique. You can read more on this here. Stackoverflow uses similar technique, but with HTML5 local storage, more on this on their blog