I am working on a project where I need to block some websites, so my approach is - whenever a person enters a URL of a specific website; it automatically redirects to another page.. for example: if a person clicks a link to enter into google.com, the browser automatically sends that person to stackoverflow.com.
here is my javascript code:
function fun(){
d=window.location.href
if (d=='https://www.google.com/') {
window.location.replace('https://stackoverflow.com/');
} else {
window.open(d);
}
}
I know it's not a good method to block a website, but IDK why my code does not work.. it would be better if suggest how website blocking actually works