How to close popup and redirect to parent window?

Let there be three windows.

GrandParent->parent->child.

GrandParent opens parent and parent opens child.

In our case child closes automatically and returns to parent. but when parent is closed it doesn’t return to GrandParent instead it goes to another tab.

I already tried the solution of creating a function in grandparent and calling it in parent. But it doesn’t work.