I have a page lets say Page1. Page1 will have a button called GoToPage2.

In the GoToPage2 button, I need to read the querystring and append its value to the url

For example: The GoToPage2 link is /sitecore/content/Sitecore/Page2 and querystring is ?id=1234 so the GTOPage2 url will be /sitecore/content/Sitecore/Page2?id=1234

What is the best way of doing this?

Any help or suggestion would be appreciated. Using SXA.

Thanks in advance

  • I think javascript could be an answer.. add some code that checks your button(s) and adjust the url on the button.
    – Gatogordo
    Jul 27, 2020 at 14:11
  • Do I need to create a custom component ? If you have any example that would be helpful
    – user2980
    Jul 27, 2020 at 14:14
  • And I need to use that button in few other pages as well. So, not sure adding javascript on every page would be an ideal solution
    – user2980
    Jul 27, 2020 at 14:15
  • I'm no js expert, but I do think that if your button can be easily found (after the page is loaded) it should be fairly easy to find and adjust them without a big impact. Creating a custom component is also an option, but I think it might be overkill
    – Gatogordo
    Jul 27, 2020 at 14:22

1 Answer 1


Achieve using simple javascript snippet

Below snippet

<!DOCTYPE html>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
      <button id="GoToPage2-Button">Get Go to page 2 url </button>
      <a id="GoToPage2-Anchor" href="https://url.com/page2-url">/page2-url</a>
         $( document ).ready(function() {
         // Get all query string value
         var querySearch = $("#GoToPage2-Anchor").attr("href")+window.location.search;
         alert("Formatted url is: " + querySearch);

Output enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.