Reputation: 2291
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?
Upvotes: 0
Views: 155
Reputation: 4634
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.
Upvotes: 2