window.opener.location.indexOf()函数问题

Gov*_*iya 4 javascript indexof window.opener

如果主机名与父母和孩子相同,我试图关闭子窗口

<script type="text/javascript">
    $(document).ready(function () {
        if (window.opener) {
            if (window.opener.location.indexOf(document.location.hostname) != -1) {
                window.opener.location = window.location;
                window.close();
            }
        }
    });
</script>
Run Code Online (Sandbox Code Playgroud)

并得到这个错误

Error: window.opener.location.indexOf is not a function
Source File: https://example.com/default
Line: 100
Run Code Online (Sandbox Code Playgroud)

Mat*_*all 9

location对象不是字符串,数组或具有indexOf方法的任何其他对象.也许你打算用opener.location.href.indexOf(...)