Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if parent window is iframe or not

People also ask

How do I check if an iframe exists?

If you wish to check if there is any iframe at all, you could use getElementsByTagName('iframe'). To make live a little easier, you can take a look at jQuery. This is a Javascript library that helps you to create DOM objects and/or find them in the DOM tree.

How do I know if a website is loaded in iframe?

The X-Frame-Options HTTP response header can be used to indicate whether or not a browser should be allowed to render a page in a <frame> , <iframe> or <object> . Sites can use this to avoid clickjacking attacks, by ensuring that their content is not embedded into other sites.

How do I turn off iframe parent window?

window. close(); or this: top. window. close(); you should be able to close it.


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).


Check if window.frameElement is not null and see if its nodeName property is "IFRAME":

var isInIframe = window.frameElement && window.frameElement.nodeName == "IFRAME";

var isInIFrame = (window.location != window.parent.location);
if(isInIFrame==true){
    // iframe
}
else {
    // no iframe
}