JavaScript
Article

jQuery Check if Window is in iFrame

By 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:

Free Guide:

7 Habits of Successful CTOs

"What makes a great CTO?" Engineering skills? Business savvy? An innate tendency to channel a mythical creature (ahem, unicorn)? All of the above? Discover the top traits of the most successful CTOs in this free guide.

  • 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.

      • Versitek

        if you want to try to fool search results in this manner, just put “not jQuery” in the title rather than deceiving the search engines. false H1 tags can get you a penalty in Google. However, using “not jQuery” will still turn up this as a result with that keyword without the penalty.

  • 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.

  • http://www.gringoinpanama.com/ Christian Rios

    Gracias!

Recommended
Sponsors
Because We Like You
Free Ebooks!

Grab SitePoint's top 10 web dev and design ebooks, completely free!

Get the latest in JavaScript, once a week, for free.