1

When I click search button the url parameter is taking care of. I need to change that url parameter name and value using jquery.

per example: search button clicked

http://testsite/_layouts/OSSSearchResults.aspx?k=deana&cs=This%20Site

Replace with:

 http://testsite/_layouts/OSSSearchResults.aspx?k=deana&s=All%20Sites

I can not modify search button functionality, because it is out of the box functionality.

I can do changing url parameter and value. How can we do that?

1 Answer 1

-1

Changing the parameter of a URL should be fairly straightfoward:

var param = window.location.href;
var param_q = param.split('?');
var param_ampersand = param_q[1].split('&');
var param_eq_1 = param_ampersand[0].split('=');
var param_eq_2 = param_ampersand[1].split('=');
var new_param_name_1 = 'test';
var new_param_value_1 = 'example';
var new_param_name_2 = 'test2';
var new_param_value_2 = 'example2';
// avoid infinite loop
if ((param_eq_1[0] != new_param_name_1 || param_eq_1[1] != new_param_value_1) || (param_eq_2[0] != new_param_name_2 || param_eq_2[1] != new_param_value_2)) window.location = param_q[0] + '?' + new_param_name_1 + '=' + new_param_value_1 + '&' + new_param_name_2 + '=' + new_param_value_2;

This worked for me in Chrome/FF. This just redirects the parameter - not sure if this is what you're looking for.

EDIT:

Added a logic to handle two parameters.

2
  • But I need to change parameter name too.
    – James123
    Commented Jun 6, 2011 at 14:31
  • @James123 - changing the value of new_param_1 will change the parameter name. Is that what you need or am I misunderstanding? It will redirect test.com?some=value to test.com?test=example.
    – g_thom
    Commented Jun 6, 2011 at 14:33

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.