Last active
May 2, 2018 12:32
-
-
Save sandcastle/4269c1cab60a9e35304efe90394a3447 to your computer and use it in GitHub Desktop.
Checks if a given window is within an iframe in a safe way.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Determines if the the current window is within an iframe | |
| * in a safe cross browser model. | |
| * | |
| * @returns {Boolean} True if in an iframe, else false. | |
| */ | |
| inIframe() { | |
| try { | |
| return window.self !== window.top; | |
| } catch (e) { | |
| return true; | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Browsers can block access to
window.topdue to same origin policy. IE bugs also take place.https://stackoverflow.com/a/326076/929771