Change the URL parameter requested by the click of a button.

I apologize in advance for not being able to provide additional information, if this is not possible with limited information, I will delete the question.

So, I have a script that generates a search engine view that depends on the script (also dynamically generated), which is quite complicated, and I do not affect it.

When you click the "Apply" (search) button, the search process starts and you can see the results of the new URL with several parameters.

E. g.: http://www..example.com/...&ThisParameter=XYZ&SecondParameter=foo&ThirdParameter=bar 

My question is: is it possible to change "ThisParameter=XYZ" to something else, e. d. "ThisParameter=Something" .

The problem is that I don’t know how the URL is configured and whether this can affect it, so I need a code that just runs any URL and changes that part.

Thanks for your feedback in advance!

EDIT

I found the part of the script that affects the generated URL. When I change it in the DOM, it redirects me to the desired page.

 var options = {"FOO":123,"BAR":"ABC","ThisParameter":"STH","EXAMPLE":123, ...} 

And this is the result when you select the "copy path":

 _options[0].ThisParameter 
+1
javascript jquery
source share
4 answers

IF QUERY PARAMETERS SEQUENCE ALWAYS ALONE:

 var url = window.location.href; var lst_temp = url.split('?'); var $lst_parts = lst_temp[1].split('&'); var new_val = 'blabla'; var position = 'x'; lst_parts[x] = 'ThisParameter=' + new_val; var url_new = lst_temp[0] + '?'; url_new += lst_parts.join('&'); 

EDIT:
IF ORDERING A QUERY BOOK DO NOT KNOW BEFORE THE HANDLE, THIS:

Use this feature here: stack overflow

 function EncodeQueryData(arr_data) { var ret = []; for (var d in arr_data) ret.push(encodeURIComponent(d) + "=" + encodeURIComponent(arr_data[d])); return ret.join("&"); } 

Then read the url and split it like this:

 var url = window.location.href; var key = "ThisParameter"; var new_val = 'blabla'; var lst_temp = url.split('?'); var lst_parts = lst_temp[1].split('&'); 

Add this loop to create an associative array containing query parameters and values:

 var arr_data = new Array(); for (var index in lst_parts) { lst = lst_parts[index].split('='); arr_data[lst[0]] = lst[1]; } 

To avoid endless updates:

 var val = arr_data[key]; if (val != new_val) { arr_data[key] = new_val; var new_url = lst_temp[0] + '?' + EncodeQueryData(arr_data); window.location.href = new_url; } 
+1
source share

You cannot change the URL without reloading the page, but the following will allow you to configure. It takes the url of the current page (source unclear in explanation). If the URL you are linking to is in the href of the link, you can simply change this code

 /* get current url info using location object*/ var baseUrl = location.href.split('?')[0]; /* array of search strings */ var searchParams = location.search.slice(1).split('&'); var searchKeyToChange = 'ThisParameter'; var newVal = 'someNewValue'; var doPageReload = false; /* loop over search strings, modify appropriate one*/ for (i = 0; i < searchParams.length; i++) { var params = searchParams[i].split('='); if (params[0] == searchKeyToChange) { if (params[1] != newVal) { searchParams[i] == searchKeyToChange + '=' + newVal; doPageReload = true; } } } /* load adjusted url if new value not already set*/ if (doPageReload) { location = baseUrl + '?' + searchParams.join('&'); } 
+1
source share

Can you just replace the regex or split by ? , then on & to get an array of pairs of parameter values.

0
source share

If your question is how to dynamically change the URL in your browser using JavaScript, this is not possible (for security reasons). If you just need to request a page using then changing the URL, you can use the methods from the previous comment: window.location.replace (yourModifiedUrl);

0
source share

All Articles