Skip to content Skip to sidebar Skip to footer

How To Understand If Page Is Loaded As Iframe (external Site) Using Javascript?

I'm trying to find a reliable solution to determine if my page was loaded in iframe on external site using javascript. If iframe src located on the same domain it's preaty easy: yo

Solution 1:

You might be interested in the Coding Horror entry: We Done Been Framed. Offers an interesting technical discussion on this topic, including solutions, and frame-busting-busting.

Solution 2:

You can wrap your validation (window.location !== window.parent.location / window.frameElement) in try-catch statement which you can use to handle the exception yourself.

Solution 3:

Why don't you try a function with the following

var element = window.parent.document if (element) return "Is in a parent window" else "is not in a parent window";

Post a Comment for "How To Understand If Page Is Loaded As Iframe (external Site) Using Javascript?"