Get site-URL-parameter from iframe (same domain)

I’ve got two html pages (site, sub).
sub.html is embeded in the site page as an iframe.
On the sub page I am running the following js:

    const queryString = window.location.search;
    const urlParams = new URLSearchParams(queryString);
    const param1 = urlParams.get('param1')
    const param2 = urlParams.get('param2')
    alert (param1 + param2)

It works fine. When I open …/sub.html?param1=hello&param2=world, I end up with “Hello World”.
But the URL-parameters are on “site.html” not on sub.html.
So I open site.html?param1=hello&param2=world how do I get those URL parameters?
I read that that is not possible if both sites are not on the same domain. In my case – they are on the same domain, so that should not a problem. At the time I am just testing it locally.