write an iframe src=child.html in the page parent.html and return null using window.frameElement in child.html
the environmental background of the problems and what methods you have tried
related codes
parent.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h3></h3>
<iframe id="iframe" src="./child.html" width="500" height="300"></iframe>
<script src="./parent.js"></script>
</body>
</html>
child.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h3></h3>
<script src="./child.js"></script>
</body>
</html>
child.js
console.log("iframe window.frameElement", window.frameElement);
iframe is a window but not a top-level window, so it should not be null.
The MDN says, "return the elements embedded in the current window object (such as < iframe > or < object >), and return null. if the current window object is already a top-level window."
the problem is that child.js is not a top-level window, why is it also null?? Or is there something wrong with my understanding?