Languages
[Edit]
EN

JavaScript - detect if webpage is open in iframe

4 points
Created by:
christa
600

In this short article, we would like to show how to detect if website is open in iframe using JavaScript.

Quick solution:

// ONLINE-RUNNER:browser;

<!DOCTYPE html>
<html>
<body>
  <script>
      
    if (window.top !== window) {
        console.log('Website is open in iframe!');
    }

  </script>
</body>
</html>

Hint: this example displays Website is open in iframe! because runner result is open in iframe.

 

See also

  1. JavaScript - escape webpage from iframe 

Alternative titles

  1. JavaScript - detect if website is open in iframe
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join