How to override a variable parameter loaded from another script

I have a script that dynamically loads code. This is a kind of search engine. When I click the search button, the action starts and a new page opens with many options.

I want to override one of the parameters generated by the script in the new URL. The JS code is quite large and hard to read, but I found the important part in the Firebug DOM editor.

This is the URL pattern generated by the search:

http://www.example.com/...?ParameterOne=123&ParameterTwo=Two&ThisParameter=Sth&ParameterFour=Four... 

What I want to change is "ThisParameter" and change its value. This is the part edited in the DOM that does what I want:

 Foobar = { _options: [], ... var options = {"ParameterOne":123,"ParameterTwo":"Two","ThisParameter":"ABC","ParameterFour":Four,...} ... 

And this is the result of "ThisParameter" when you select "Copy Path" on the Firebug DOM tab:

 _options[0].ThisParameter 

I am wondering if this is possible at all. What makes me think that this is so is the fact that I can change this setting in Firebug, and it works great. So, if Firebug can edit it, there must be a way to influence it with another script.

We look forward to offers, thank you in advance!

+8
javascript jquery
source share
3 answers

Since you cannot edit a dynamic script, you have the following options:

  • You need to try to give the script the correct input and hope that it uses your value.
  • Add a script page to the results page that will read the URL and arguments, change it and redirect, as we discussed here. (If you put everything in a function, this should not contradict the dynamic script if the functions are uniquely named.)

You can try adding something like this jQuery code to the page using the search button:

 $('input[name=search_button_name]').click(function(e) { e.preventDefault(); var form_search = $('#search_form_id'); $('<input>').attr({ type: 'hidden', name: 'ThisParameter', value: 'SomethingElse' }).appendTo(form_search); f.submit(); }); 
+1
source share

You can override any js function and method or wrap code around it. The easiest way would be to look at the code you get, and once it loads, you will re-declare the method with your own functions.

I am trying to replace a parameter in a specific jquery query, you can even wrap ajax method around jQuery:

 var jquery_ajax = $.ajax $.ajax = function(options){ // parse only a specific occurence if(options.url.indexOf("example.com") > -1) { // change the url/params object - depending on where the parameter is options.params.ThisParameter = "My Custom value" } // call the original jquery ajax function jquery_ajax(options); } 

But it would be much cleaner to override the method that builds the ajax request, not the ajax request itself.

0
source share

I would also investigate the scope of variables ( var options ), is it global? those. if you type β€œoptions” in the Firebug console, will its properties be displayed?

If so, you can access it through your own script and change the value, for example.

 options.ThisParameter = 'my-own-value'; 

You can connect your script to the search button click event.

I hope this helps, it could be more specific, perhaps if you have some sample code.

0
source share

All Articles