IE Blocking iFrame Cookies

I got a call today about one of my applications not running correctly from inside an iFrame. I tried it out and it looked like everything worked great in Safari and Firefox but not IE6 or IE7. It took me a few failed attempts to fix it before I decided it must be a session problem. After firing up a packet sniffer it became obvious the cookie with the session ID was not being passed.

The problem lies with a W3C standard called Platform for Privacy Preferences or P3P for short. You can read all about the boring stuff via the link or else just install the P3P Compact Policy header below. This will allow Internet Explorer to accept your third-party cookie. You will need to send the header on every page that sets a cookie.




HttpContext.Current.Response.AddHeader("p3p","CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"");


response = render_to_response('mytemplate.html')




I understand that the P3P header will have to added to the app running inside the iFrame. How about the parent site hosting the iFranme? Does the parent site need to publish some P3P policy also in order for the embedded iFrame to work correctly?

Nope, just the site in the iFrame

Is there a solution for Ruby On Rails, too?

I have a default.aspx page that is just a plain html frame, top page is a search and bottom page is a result.

do I need to put this in all three pages or just the default.aspx page that is called by the iframe.

Note, that by using such a P3P statement, you're making a legal statement about how your application handles cookies. If you're later found in violation of the statement you make, you will find yourself in criminal and civil jeopardy.

This got me out of a tight squeeze. Thank you very much.

Hi Adam,

I've read a plethora of examples of P3P working for people, but in my case, the most simple example just doesn't want to work for me. Am I doing something wrong?

The is the container page:

&lt;% response.addHeader("P3P","CP='IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT'"); %&gt;
&lt;h2&gt;iframe container&lt;/h2&gt;
&lt;iframe src=""&gt;&lt;/iframe...

This is the page which is IFRAMEd in:

&lt;% response.addHeader("P3P","CP='IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT'"); %&gt;
function setCookie() {
document.cookie = "cookie_text=cookie set by inner iframe; path=/; expires=Sat, 31 Oct 2009 22:00:00 UTC;";
function clearCookie() {
document.cookie = "cookie_text=blank; path=/; expires=Fri, 27 Jul 2001 02:47:11 UTC;";
&lt;h2&gt;inner frame&lt;/h2&gt;
&lt;a href="javascript:setCookie()"&gt;set cookie&lt;/a&gt;
&lt;a href="javascript:clearCookie()"&gt;clear cookie&lt;/a&gt;

Example can be found here:

When I attempt to call the setCookie function in the IFRAME page, I get the dreaded red eye, and the Privacy Alert msg comes up, because I have my browser set to "Prompt" for Third Party Cookies.

Under Internet Options - Privacy - Advanced, I have Override automatic cookie handling checked, and Third-Party cookies set to prompt.

Any feedback anyone has would be much appreciated! If you have an example which works, I'd love to see it too.


this made my day

Thanks a lot!

it solved my
hta, php, session, cookie, login

You made me very very happy.. short and simple! thanks alot!

Well... it works on IE but not in HTA !

I lost 2 hours on this fu!#@? problem...

now it just works...

Thanks for sharing !

We added that header to our httpd.conf and it worked like a wonder.

You just saved my day!!!!!

Thanks for sharing dude!!!

If you ever come to Amsterdam i'll buy you a beer!!

omg, you saved my day too :)

IE is nothing but headaches..


You literally saved a handful of hairs on my head with this work around.

Thanks for your time!

- Al

P.S. If you are having issues with calling in Kayako support suite using Iframes this works.

Thank you Very Much it's working just fine

Awesome. Just awesome :P !

Thank you for this, I'm sure I would have been going around in circles for hours without this fix!

i love it when theres such an easy fix!

I thought I was screwed when I checked IE and found my application wasn't keeping cookies set in iframes. Just one line saved the day! Thanks!

Thanks for the useful instruction :-)
I was using this in our dev site, but today I need to put it on our production site, so I learned how to generate a P3P policy as I think would be better to generate our own if using on production site, so here is the instruction if anybody needs to do so

you solve my problem so easy!!!

Thank you for this from my friend Rasha.

Even with the P3P header added, you can still get into trouble if IE7 submits a request for a cached page, and the response is 304 not modified. That header-only response does NOT include the P3P header element... and if it _also_ attempts to set a cookie, IE7 gets upset and destroys the cookie... and worse still, blocks the site.

So, I eventually fixed this problem by ensuring that no 304 not modified response was ever generated (by setting the etag anew w each response).

This worked for us initially, but would not work with the following meta tag:

<code>meta http-equiv="Content-Type" content="text/html; charset=utf-8"</code>

I had to remove the meta tag, and set the content type with php:

<code>header('Content-Type: text/html; charset=utf-8');</code>

Thank you very much, you saved my day!

I was getting mad solving why my iframe facebook app won't work in IE. You are evil genius!

This does not work in IE8

Hi, IE8 is not working me as well. Did you find a solution for it?


It works for IE8. I added this inside Page_Load method
HttpContext.Current.Response.AddHeader("p3p", "CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"");


Saved my day too! Thank you very much!

It's wonderful, small thing made large difference. Thank you.

I'm a novice programmer, more of a web site making feller. We're sending out a national campaign and needed to have a framed version of our website in another domain for a degree of separation. This of course made the cookies useless in IE7 until stumbling across this fix. I was only half an hour deep but it couldv'e been all day. Thank you so much!!!!

I was near to suicide when found your article. Thanks a lot, you're my Lord. (Die, IE, die!)

I had the same problem once, and the way I solved it was by using a proxy script, that way everything was dereferenced to my current domain and iframe cookies were no longer third party. :)

Hi, i'm interested in your solution can you inform me how you did it?
Thank you

response.headers['P3P'] = 'CP="NON DSP COR CURa IVAa IVDa CONa OUR NOR STA"'

You've a wonderful wonderful man. I'd protect you in prison.

I Have an application. I have added the P3P Policy as mentioned, but my page still gets refreshed wen i try to login. Below is my code....

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<% HttpContext.Current.Response.AddHeader("p3p", "CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\""); %>

<iframe id="frame1" src="" runat="server" width="100%" height="400px"></iframe>

Here's our issue...will this help???

We have the coolest interactive survey ever created and it requires a cookie to run it.
Works great in direct link or even (interactive survey that tells you how normal you are in a relationship or single...super cool!!!)

Anyway Reader's Digest (80 million readers) put in the magazine and on the homepage today. Yes, this is a big deal and I will owe somebody hugely on a fix for this! So it's live on homepage, but if you have internet explorer and the default is set to medium or high security, it doesn't work! UGGGGGG! Figured I could cry or try to call out for help.

So, we need the cookie (which is third party via Reader's Digest iframe) and we need it to run on internet explorer without telling people with IE to set security to low. That's not an option.

We code can we put in the survey so it will run within the iframe and ie????

Feel free to email me directly or I will check back on this blog on the hour for answer.

Take the cool survey and let me know what you think! It's really funny and gives fun payback.

xo Chrisanna

I meant to say which code can we put in survey so it will run with iframe via ie without this error:

HTTP Status 500 -


type Exception report


description The server encountered an internal error () that prevented it from fulfilling this request.



note The full stack trace of the root cause is available in the Apache Tomcat/5.5.20 logs.

Thanks a lot for sharing that "beyong totally crazy" information !
You just saved my day too :)

pure genius ! great job

I have a web site that is just a plain .asp page. How would you put this in there. (sorry new to this). What about the page load issue with IE8? Any help would be appreciated

Did you get this resolved??? I have the same issue.

You save my day! Thanks a lot!

You are. That was becoming a serious pain in the neck until I found your fix - many thanks.

I'm looking for a quick copy-and-paste of what to put as the PHP code, but I'm not too keen on PHP myself. Here's what I've come up with from reading the comments:

<code><?php Page_Load method
HttpContext.Current.Response.AddHeader("p3p", "CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\""); ?></code>

I'm just needing to find the full code to see if the iframe issue with IE is the problem users are having on my site. Anyone want to paste the code they used? This one doesn't seem to do anything... :/

thousand thanks.