How to access the same site cookie when in iframe?

Member

by jerad , in category: Javascript , 7 months ago

How to access the same site cookie when in iframe?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by herminia_bruen , 7 months 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.

Related Threads:

How to access to iframe inside iframe?
How to allow http content within an iframe on a https site?
How to access the servlet results from an iframe?
How to access elements inside an iframe?
Database update
How to access the <img /> in document from iframe?