'Can an iframe know if it is in viewport? The ifram is not of same origin

I have an iframe that goes inside another page. I do not have control over the other page content, and they are not of same origin. I want to do some actions only when a user sees the iframe. Can I determine from inside the iframe if it is in the viewport?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source