Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

Commit

Permalink
fix: fix getOrigin issue within iFrames (#175)
Browse files Browse the repository at this point in the history
* fix:#136

* destructuring
  • Loading branch information
zlyfenek authored and wuweiweiwu committed Jun 19, 2019
1 parent f1858a3 commit f290cb3
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;
// 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 f290cb3

Please sign in to comment.