cosmos-explorer/src/Utils/WindowUtils.ts

19 lines
658 B
TypeScript
Raw Normal View History

2021-01-20 09:15:01 -06:00
export const getDataExplorerWindow = (currentWindow: Window): Window | undefined => {
// Data explorer is always loaded in an iframe, so traverse the parents until we hit the top and return the first child window.
try {
while (currentWindow) {
if (currentWindow.parent === currentWindow) {
return undefined;
}
if (currentWindow.parent === currentWindow.top) {
return currentWindow;
}
currentWindow = currentWindow.parent;
}
} catch (error) {
// Hitting a cross domain error means we are in the portal and the current window is data explorer
return currentWindow;
}
return undefined;
};