I got a task to do something whenever my page will get redirect to a different page on click of any link or button. So i need a general event under which i can run my code. I need it throughout the application and can’t give each and every link and button a common class as a selector which will be redirecting a page to a different one since it’s an old app.
I think the question is how to determine if it’s an external link? In this case you might check the .origin property of the anchor element against the window.location.origin: