Simon
Simon

Reputation: 11

Is it possible to block cookies within an iframe?

Is it possible to force an iframe to load without cookies and create an entirely new session for the user?

For example: could I include an <iframe src="https://stackoverflow.com"> on a site such that even a currently logged-in StackOverflow user would not be automatically logged in?

An "incognito mode" iframe, if you will.

Upvotes: 0

Views: 4898

Answers (2)

Shahryar Mohajer
Shahryar Mohajer

Reputation: 589

if you want iframe don't set cookies and render correctly:

<iframe sandbox="allow-scripts" src="..."></iframe>

if you want only not showing iframe:

  <iframe id="FR" src="">

in java script:

document.getElementById("FR").style.display = "none";
document.getElementById("FR").style.visibility = "hidden";

Upvotes: 0

Libra
Libra

Reputation: 2595

The HTML5 sandbox attribute (without allow-same-origin keyword) prevents an iframe from reading/writing cookies. This is true for both same-origin and cross-origin iframes.

The allow-scripts attribute will enable JS, but will not interfere with restrictions on cookies.

<iframe sandbox="allow-scripts" src="..."></iframe>

-via Chava G Recommended method to prevent any content inside iframe from setting cookies

Upvotes: 1

Related Questions