I suggest you try to check the substring of the user agent may help to identify the IE and Edge legacy browser. Then if it is an IE or Edge legacy browser then you can show a message to the users to use the MS Edge Chromium browser. If it is any other browser then it will let users visit the site.
Sample code:
<!doctype html>
<html>
<head>
</head>
<body>
<div id="info"></div>
<script>
function detectIE() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf('MSIE ');
if (msie > 0) {
return "IE " + parseInt( ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
}
var trident = ua.indexOf('Trident/');
if (trident > 0) {
var rv = ua.indexOf('rv:');
return "IE " + parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
}
var edge = ua.indexOf('Edge/');
if (edge > 0) {
return "Edge " + parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
}
// other browser
return "false";
}
var result=detectIE();
if (result=="false")
{
document.getElementById("info").innerHTML +="<h2>Welcome to the site...</h2>";
}
else
{
document.getElementById("info").innerHTML += "<h2>Dear user you are using " + result + " This browser is not supported by this site. Kindly use MS Edge Chromium browser...</h2>";
//console.log(result);
}
</script>
</body>
</html>
Output:

Referenced answer:
How can I detect Internet Explorer (IE) and Microsoft Edge using JavaScript?
Further, you can modify the code sample as per your own requirements.