I try to close the child window if the host name matches the parent and child, but
<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 get this error
Error: window.opener.location.indexOf is not a function Source File: https://example.com/default Line: 100
The location object is not a string, array, or any other object that has the indexOf method. Perhaps you wanted to use opener.location.href.indexOf(...) ?
location
indexOf
opener.location.href.indexOf(...)
The problem is that location not String , it is a location object. You can use the toString location method to convert it to a string:
String
toString
window.opener.location.toString().indexOf(document.location.hostname)
Source: https://habr.com/ru/post/1387837/More articles:How to add some values ββthat were created in a while loop using Python - pythonReplace characters in a field on a submit form - javascriptJava: JPanel cannot receive key events after clicking a button (which does not have a registered event listener)? - javaSecurity Issues with Dynamic Latex Linking on a Web Server - phpJavascript Toggle Onclick Dropdown - javascriptBest way to put javascript in an xcode project - javascriptJ2ME streaming audio over a SIP connection - java-meCreating a ".rc" file in Visual Studio 2010 Express - windowsCan I use Couch DB or MySql or any other DB in Android? - androidHow to specify threads in WinDbg (kernel debugging) - multithreadingAll Articles