JavaScript – Check if a webpage is being loaded inside an iframe or directly into the browser window

window.frameElement Returns the element (such as <iframe> or <object>) in which the window is embedded, or null if the window is top-level. So identifying code looks like

 Reference

Standard method – https://developer.mozilla.org/en-US/docs/Web/API/Window/frameElement