Is window.frameElement (for frames of the same origin) supported in all browsers?

I have googled as much as possible, and I'm not sure of the support of the iframe document, which itself is an identifier in the parent window: window.frameElement.id. There are so many browsers that it’s hard to test them, and nothing on the Internet has any information. I am particularly interested in:

Safari iOS Safari Windows Phone IE IE 7, 8, 9, 10, 11

(I tested Firefox and Chrome, and they both worked).

EXAMPLE CONTENT IFRAME

<!DOCTYPE HTML>
<html>
    <head></head>
<body>
        <script type="text/javascript">
            var owner = window.frameElement;
            var thisIsWhoIsCalling = ( owner !== null ) ? owner.id : null;
            window.parent.SomeJavaScriptObject.someFunction( thisIsWhoIsCalling );
        </script>
    </body>
</html>
+4
source share
2 answers

I had to look for the same information. Here is what I found.

https://developer.mozilla.org/en-US/docs/Web/API/Window.frameElement

MDN , IE7 +, Safari, Firefox, Chrome. .

IE6, , , .

+3
var frame = window.frameElement;  //Get <iframe> element of the window
if (frame) { window.location.href = "/403.shtml"; ...

- (FF, Chrome, IE) , ...

  if (window.self === window.top) window.location.href = "/403.shtml";
//or if (window.self !== window.top) window.location.href = "/403.shtml";
0

Source: https://habr.com/ru/post/1537899/


All Articles