0

I want to check whether the loaded page is loaded directly from browser or called inside any frame including Facebook application as canvas page.

This is really important for me. I found out this question How to identify if a webpage is being loaded inside an iframe or directly into the browser window? but some people said that it doesn't work at some browsers ?

I can also use jquery if that provides better solution or this solution is the best ?

Thank you very much for the answers

function inIframe () {
    try {
        return window.self !== window.top;
    } catch (e) {
        return true;
    }
}
Community
  • 1
  • 1
Furkan Gözükara
  • 22,964
  • 77
  • 205
  • 342
  • You do not want to use !== since in IE, self and top refer to two different proxy objects, and you will get a false positive. Use != instead. – Sean Kinsey Mar 06 '14 at 05:33

1 Answers1

1

http://www.jquery4u.com/snippets/jquery-check-window-iframe/

function isIframe() {
var isInIframe = (window.location != window.parent.location) ? true : false;
alert(isInIframe);
}
douwe12345
  • 65
  • 1
  • 1
  • 7