'How do I prevent a link inside an iframe from opening in a new tab?

I'm new to Html and Javascript. I've been making an iframe browser with the help of an extension. see my GitHub page One of the issues my users face is that some links and redirects that occur in the iframe open in a new tab. How do I prevent this and allow the redirects and links(when clicked on) to open in the iframe? If not possible, is there a way to get the URL of the link before the page is redirected?

I tried adding <base target="_self"> in the head of the page.



Sources

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

Source: Stack Overflow

Solution Source