0

Background: I have a website that has multiple tabs running on server B. One of these tabs contains an iframe that is loading an Angularjs based site that is running on a separate server (server A). The site refreshes sections every 10 seconds to check for changes made elsewhere. When not on that tab, I want to block these calls. I need to find a way to detect whether the page is rendered and block the calls if it is not from within the server A.

Current solution: In Firefox I have got this working using getBoundingClientRect().top on an element. The value changes when another tab is loaded so can check it and block the calls. This doesn't work in Chrome though. The value doesn't change when swapping tabs.

Does anyone have any suggestions or experience with this? Need a solution that will work in all browsers.

Hedhog
  • 1
  • 1
  • Possible duplicate of [Detect If Browser Tab Has Focus](https://stackoverflow.com/questions/7389328/detect-if-browser-tab-has-focus) – jmargolisvt Jul 18 '17 at 15:32
  • You can use `window.location.ancestorOrigins` at Chrome, Chromium and `document.domain` at Firefox, see [Foolproof way to detect if this page is INSIDE a cross-domain iframe](https://stackoverflow.com/q/21751377/) – guest271314 Jul 18 '17 at 15:36
  • Possible duplicate of [Is there a way to detect if a browser window is not currently active?](https://stackoverflow.com/questions/1060008/is-there-a-way-to-detect-if-a-browser-window-is-not-currently-active) – Daniel Beck Jul 18 '17 at 19:32

1 Answers1

0

Thank you for the suggestions.

Fixed this using: parent.document.getElementsByTagName('iframe')[0].getBoundingClientRect().top

In all browsers this value changes when the iframe is no longer on the active page.

Hedhog
  • 1
  • 1