Friday, June 3, 2011

Cookie settings problem in IE for Facebook iFrame Applications

Recently I was working on a iFrame Facebook application where I faced a problem with cookie in Internet Explorer. I was using cookie to make authenticated API calls from server. This was working fine for all browsers except IE. The cookie was not working with the default cookie settings of IE. As the cookie was getting set in an iframe, IE view it as a third-party cookie and rejects it as the default cookie setting for IE does not allow third-party cookies. The solution for this problem was to have a compact privacy policy on the pages where cookies are needed. Having a compact privacy policy is easy. You need set a compact P3P header on the required pages. I needed to set the following PHP header to solve my problem:
header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');

Changing parent window's url from iframe

Sometimes it is needed to change the parent window's url from iframe. It is pretty easy to do with javascript. You need to execute the following javascript from the iframe whenever you want to change parent window's url:
parent.location = "YOUR REDIRECT URL";
That's it.