How to set a cookie for another domain

后端 未结 11 1921
一向
一向 2020-11-22 07:21

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

11条回答
  •  Happy的楠姐
    2020-11-22 07:53

    You can't, but... If you own both pages then...

    1) You can send the data via query params (http://siteB.com/?key=value)

    2) You can create an iframe of Site B inside site A and you can send post messages from one place to the other. As Site B is the owner of site B cookies it will be able to set whatever value you need by processing the correct post message. (You should prevent other unwanted senders to send messages to you! that is up to you and the mechanism you decide to use to prevent that from happening)

提交回复
热议问题