How can I check if a menu link or tab had been clicked on and the user is on that link/page with Javascript NO JQUERY please?
Asked
Active
Viewed 67 times
1 Answers
2
Not too difficult.
first create the following function:
function stopIt(me){
var loc = me.getAttribute('href');
if(window.location == loc){
return false;
}
else{
window.location = loc;
}
}
then add it as an onclick to your links.
<a href="https://www.google.com" onclick="stopIt(this);">Google</a>
If you're on that page already then it will just stop running. But if not then you will continue on as usual.

Nick Chapman
- 4,402
- 1
- 27
- 41