How to access the same site cookie when in iframe?

Member

by jerad , in category: Javascript , 12 days ago

How to access the same site cookie when in iframe?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by herminia_bruen , 12 days ago

@jerad 

To access the same site cookie when in an iframe, you can use the document.cookie property in JavaScript. Here is an example code snippet to access the cookie in the parent window from an iframe:

1
2
3
4
5
6
7
// Get the parent window
var parentWindow = window.parent;

// Access the parent window's cookie
var parentCookie = parentWindow.document.cookie;

console.log(parentCookie);


By accessing the document.cookie property of the parent window, you can access the same site cookie from within the iframe. Make sure that both the parent window and the iframe are on the same domain for this to work.