1

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 at 14:11
  • Do I need to create a custom component ? If you have any example that would be helpful – Owais Ahmed Jul 27 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 – Owais Ahmed Jul 27 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 at 14:22
0

Achieve using simple javascript snippet


Below snippet

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

Output enter image description here


| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.