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.
Related posts:

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