jQuery Check if Window is in iFrame

Sam Deering

Simple JavaScript code snippet to check whether or not a window is in an iFrame. Very useful for some functions that may make use of the URL in the address bar of the page.

Simple as this.

var isInIframe = (window.location != window.parent.location) ? true : false;

Also See:

Get your free chapter of Level Up Your Web Apps with Go

Get a free chapter of Level Up Your Web Apps with Go, plus updates and exclusive offers from SitePoint.

  • http://nadda Yogi

    This is pure javascript, why did you label it as jquery?

    • jquery4u

      @Yogi, labelled as jQuery for Google Search Keyphrase as some people search for jQuery even though a good solution sometimes lies with regular JavaScript.

  • Tingo

    I wonder if window !== window.parent works for this purpose across all platforms. It works in Chrome on OS X.

  • Ferlle

    Thank you, it helped me :)

  • David Fritch

    Great! Thanks.