Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
zlyfenek committed May 22, 2019
1 parent f1858a3 commit 2a686d8
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@ export function getWindowHeight() {
// Get the highest window context that isn't cross-origin
// (When in an iframe)
export function getHighestSafeWindowContext(self = global.window.self) {
const referrer = self.document.referrer;
// If we reached the top level, return self
if (self === global.window.top) {
if (self === global.window.top || !referrer) {
return self;
}

const getOrigin = href => href.match(/(.*\/\/.*?)(\/|$)/)[1];

// If parent is the same origin, we can move up one context
// Reference: https://stackoverflow.com/a/21965342/1601953
if (getOrigin(self.location.href) === getOrigin(self.document.referrer)) {
if (getOrigin(self.location.href) === getOrigin(referrer)) {
return getHighestSafeWindowContext(self.parent);
}

Expand Down

0 comments on commit 2a686d8

Please sign in to comment.