0

I currently have this javascript snippet which loads a URL depending on the dropdown selection...

   var orderby = jQuery('#dropdown');
        var str;
        orderby.change(function(){
        str = jQuery(this).val();
        window.location.href = "http://www.example.com?variable="+str;
    });

Is there a simple way to modify this so that instead of going to http://www.example.com?variable=str it just adds variable=str to the end of the current url and then redirects to it?

EDIT

Didn't make things clear, I still want to redirect but instead of specifying the new URL I want to take the current URL + variable and then redirect

fightstarr20
  • 8,600
  • 24
  • 103
  • 203

2 Answers2

1

Just make

window.location.href = window.location.href + "?myVar=awesomeValue"
0

window.location = the URL your browser get for the last time (in the actual view)

If you modify it with window.location, your browser will change your location, and so get another page.

If you use @fatih solution, you will modify the actual page url in the history (so, just a string, not your window location). So your browser won't get another page.

I'm not sure that you can get the GET variables from urls you changed, this is depending on HTTP protocol, out of my knowledges.