EN
JavaScript - detect if webpage is open in iframe
4
points
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 iniframe.