Reputation: 13753
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
Upvotes: 4
Views: 4367
Reputation: 22941
The problem is that location
is not a String
, it is a Location
object. You can use toString
method of location
to convert it to string:
window.opener.location.toString().indexOf(document.location.hostname)
Upvotes: 2
Reputation: 359966
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(...)
?
Upvotes: 10