Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.opener.location.indexOf() function issue

I am trying to close child window if host name are same of parent and child but its

<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>

and getting this error

Error: window.opener.location.indexOf is not a function
Source File: https://example.com/default
Line: 100
like image 218
Govind Malviya Avatar asked Dec 17 '22 05:12

Govind Malviya


1 Answers

The location object is not a string, array, or any other object which has an indexOf method. Perhaps you meant to use opener.location.href.indexOf(...)?

like image 71
Matt Ball Avatar answered Dec 18 '22 19:12

Matt Ball