How to check if an element is inside an iframe or not?

by jasen_gottlieb , in category: Third Party Scripts , 8 months ago

How to check if an element is inside an iframe or not?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by jerad , 8 months ago

@jasen_gottlieb 

To check if an element is inside an iframe or not, you can use the window object to access the frameElement property. This property will return the <iframe> element if the current page is inside an iframe, or it will return null if the page is not inside an iframe.


Here is an example code snippet to check if an element is inside an iframe:

1
2
3
4
5
if (window.frameElement) {
  console.log('Element is inside an iframe');
} else {
  console.log('Element is not inside an iframe');
}


You can run this code snippet in the browser's console while inspecting the element you want to check. If the element is inside an iframe, the console will log "Element is inside an iframe", otherwise it will log "Element is not inside an iframe".

Related Threads:

How to check if dynamic element is visible inside of the iframe?
How to clear an element inside an iframe?
How to get element inside iframe by cypress?
How to create a canvas element inside an iframe?
How to apply 'offset' to an element inside an iframe?
How to check if element is being loaded by iframe?