0

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?

Adrian
  • 2,273
  • 4
  • 38
  • 78

1 Answers1

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