1

I try to test the function s.Util.getQueryParam.

The url I have is in format

http://project1/project1.html

I would like to add some parameters in the url after that in order to have something like this format

http://project1/project1.html/?id=03

I try to use this example

// www.mysite.com/my_app.html?Use_Id=abc 

var GET = {};
var query = window.location.search.substring(1).split("&");
for (var i = 0, max = query.length; i < max; i++)
{
    if (query[i] === "") // check for trailing & with no param
        continue;

    var param = query[i].split("=");
    GET[decodeURIComponent(param[0])] = decodeURIComponent(param[1] || "");
}

I try to add in Get this id=03 but it is not working when I refresh my browser I can't see the parameter. Is it possible to help me how can I run it with the right way?

Community
  • 1
  • 1
Demi Kalia
  • 123
  • 1
  • 1
  • 9
  • That snippet of code is for extracting parameters from the URL, not adding them to the URL. Are you trying to add parameters to the URL, inside the web browser? If so, why? – harmic Jul 06 '15 at 07:33
  • @harmic Yes I try to add parameter to url in order to test locally some analytics urls. Also I show this example (http://stackoverflow.com/a/487049/5018097) but I am not pretty sure for key and value. Any help if it possible please? – Demi Kalia Jul 06 '15 at 07:35
  • possible duplicate of [Add / Change parameter of URL and redirect to the new URL](http://stackoverflow.com/questions/13063838/add-change-parameter-of-url-and-redirect-to-the-new-url) – Simpal Kumar Jul 06 '15 at 07:42
  • @Mike thank you but what should I use in order to test the answer with the paramName and paramValue – Demi Kalia Jul 06 '15 at 07:44

1 Answers1

3

You can modify window.location.search to add query parameters. This will cause the browser to load the new URL (the page will be refreshed).

Example: window.location.search = '?id=03'.

Matthew King
  • 1,242
  • 6
  • 13
  • Thank you it was worked for me but with an unexpected way. I can see the parameters in url but it always shows that it is loading and I can't see the content of the page – Demi Kalia Jul 06 '15 at 07:38