Why is there no result for alert (opener.name)?

The

textbook says: alert (opener.name) can get the name of the parent window.

cat father.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <script>
    window.open("file:///tmp/child.html");
    </script>
</body>

i am father window

</html>

cat child.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script>
        alert(opener.name);
    </script>
</head>
<body>
    

i am child window

</body> </html>

enter file:/tmp/father.html in the browser and child.html will open, but why is there no alert window open?

Apr.11,2021

opener is not defined.: Uncaught TypeError: Cannot read property 'name' of null, is reported directly when getting opener.name, so it will not alert


throw it to the server to execute


is it possible that the browser security policy? You must have made a mistake. Just take a look at the error message.

it is not possible to obtain the file protocol in this way, at least change it to http protocol

Menu