How do I add a value to the end of the address bar using js?

  • 0
    Hello, I have a tag with a link & lt; a & gt; I need to make it so that when the user clicks on this link, the page is refreshed and & amp; sort = p.price & amp is added to the end of the address bar ; order = ASC . For example:

    The person who came to my site, went to the products page, now, when he has not yet clicked this link, the link looks like this:
    https://miturbo.ru/index.php?route=product/category&path=711


    And when he clicks on the link which in the & lt; a & gt; tag, & amp; sort = rating & amp; order = DESC is added to the end of the address bar. As a result, when the page is refreshed already with the value & amp; sort = rating & amp; order = DESC at the end of the line, in the end the link should look like this:
    https://miturbo.ru/index.php?route=product/category&path=711&sort=rating&order=DESC


    Not like this:
    https://miturbo.ru/index.php?route=product/category&path=711/&sort=rating&order=DESC

    And like this:
    https://miturbo.ru/index.php?route=product/category&path=711&sort=rating&order=DESC


    Maybe this can be done somehow using onclick? Here is the html code itself:
    <div class="sorted_item"><a class="sorted__link" href="Сюда незнаю что вставить" "А здесь может быть onclick?">Новизне</a></div>


    I will also say that the link itself can be different, it can be https://miturbo.ru/asdnfweln this is the main thing to add & amp; sort = rating & amp; order = DESC to the end.

    I'll be very thankful.
    JavaScript Everly Holden, May 30, 2019

  • 2 Answers
  • 0
    If with an ax, then:

    <a href="#" onclick="location.search += '&sort=rating&order=DESC'; return false;">Текст ссылки</a>




    Of course, we need to refine the processing of conditions and the generation of the required string with get parameters.
    Anonymous

  • 0
    Link A can be made a button or you can add a Submit method. Put everything in the form with the GET method and make the sort and order as hidden input fields.
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!