Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
151
rated 0 times [  155] [ 4]  / answers: 1 / hits: 103672  / 14 Years ago, tue, january 4, 2011, 12:00:00

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



Explanation:



My home page home.html contains an iframe



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


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



Code in sample.html:



if(self==window)
{
alert('home.html is not in iframe');
}
else
{
alert('home.html is in iframe');
}


My question is not a duplicate. It's a different case.


More From » jquery

 Answers
6

This is true if a window is not a frame/iframe:



if(self==top)


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



if(parent==top)


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


[#94386] Sunday, January 2, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
harleyaleenag

Total Points: 678
Total Questions: 121
Total Answers: 105

Location: Papua New Guinea
Member since Thu, Jul 9, 2020
4 Years ago
harleyaleenag questions
Thu, May 5, 22, 00:00, 2 Years ago
Wed, Aug 19, 20, 00:00, 4 Years ago
;