Each frame has its own window variable. To get this variable for the parent window, you can use the window.parent property.
However, there is a problem with your task. Due to the same-origin limitations in fairly modern browsers, it is not possible to find out the address of the “not your” parent frame (the location.href property in the “write only” access mode). Therefore, you can try to read the location.href property of the parent frame. If there is an exception, then the parent frame is “alien”.
Accordingly, your check may look like this:
var countAlienDomains, frameParent, frameHref; countAlienDomains = 0; frameParent = window; while (frameParent != frameParent.parent) { frameParent = frameParent.parent; try { frameHref = frameParent.location.href; } catch (e) { countAlienDomains += 1; } } console.log(countAlienDomains);