Mohan Ram Mohan Ram - 1 year ago 135
Javascript Question

to check parent window is iframe or not

How can I tell from a page within an iframe, if the parent itself is also within an iframe?


My home page

contains an iframe

<iframe src="sample.html"></iframe>

I need to detect if home.html (ie: parent of sample.html) is within an iframe.

Codes in sample.html

alert('home.html is not in iframe');
alert('home.html is in iframe');

My Question is not a duplicate. It's a different case. Help me.

Answer Source

is true if a window is not a frame/iframe

if you like to see if the parent window of the given window is a frame, use


It's a simple comparision of top(the most top window of the window-hierarchy) and another window-object(what self or parent are)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download