0

My links are like that:

index.php
index.php?do=that
index.php?do=this

And my current javascript code is like that:

var url = window.location.pathname, 
    urlRegExp = new RegExp(url.replace(/\/$/,'') + "$");
    console.log(url);
    $('.nav-link').each(function(){
        if(urlRegExp.test(this.href.replace(/\/$/,''))){
            $(this).addClass('active');
        }
    });
});

So with this code even if I'm at index.php?do=this console log says to me /path/index.php

I think I need make changes on var url = window.location.pathname line but I couldn't.

How should I improve my code? There are bunch of similiar questions here in SO, but not the same one.

I appreciate any help.

Lukasz
  • 409
  • 3
  • 11

1 Answers1

1

In PHP you can get your URL parameters from GET array. $_GET['do'] or try to print $_GET. This array will print all the URL parameters. Hope this helps!

Rohit
  • 1,794
  • 1
  • 8
  • 16