Check if page is loaded in IFrame

Posted on 30. Nov, 2009 by Nikhil Sheth in Javascript, Knowledge

I was working on a page and wanted to make sure that this page is not opened in an iframe.
Here is some piece of javascript code which helps you to detect this.

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

If inFrame is true you can redirect user or throw some alert.

Share and Enjoy:
  • Twitter
  • Digg
  • StumbleUpon
  • Facebook
  • del.icio.us
  • Yahoo! Buzz
  • Google Bookmarks
  • FriendFeed
  • LinkedIn
  • Technorati
  • Yahoo! Bookmarks
  • DZone

Related posts:

  1. Firefox 3.5 arrives
  2. Looking at different side of Web Analytics
  3. To HUP or nohup?
  4. Stop Users from Right-Clicking on Your Web Site
  5. Spice up your Gmail

Tags: ,

One Comment

Leslie

30. Nov, 2009

nice
but you can also use a better method
window.parent returns the immediate parent window.

so if you have an iframe inside another iframe this will not work.

so instead of window.parent.location use window.top.location

window.top returns the topmost parent :)

Leave a reply

Anti-Spam Protection by WP-SpamFree

Get Adobe Flash playerPlugin by wpburn.com wordpress themes