'Close Window opened manually in script

I am trying to close the current tab when the user clicks on the 'CloseWindow' Button. Whatever I try

VM303:1 Scripts may close only the windows that were opened by them.

statement is displayed. I tried all the workarounds using self, window.opener.close() etc.
Has anyone done and it's working please share and help. I am using React framework. I am trying this in a jsx file.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source