javascript error: cannot read properties of null (reading ‘window’)

I am using javascript in my aspx page. code below:-

    function Refresh()
    {
       var url=opener.window.location.href;
       opener.window.RefreshTabContent();
    }

I am opening a new tab from a link, this code I have written in a new tab, that is opened opener.window.RefreshTabContent();
refreshes the previous tab, while

var url=opener.window.location.href; assigns the URL to the previous tab.

In the above code I am getting error: cannot read properties of null (reading ‘window’)
Please help where I am making error.
Thanks