The way to fix this is very simple. All you have to do is change the value of the opener property of the window class, like this:
window.opener = "Something";
Now you can close it like you normally would, like this:
This works because the permissions of the opener property are read/write, making it simple to close the primary window of a site.