I have a script that loads the code dynamically. It is kind of a search engine. When I press a search button, the action gets triggered and a new page opens with many parameters.

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

This is the pattern of the URL generated when you perform the search:

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

What I want to edit 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 output of "ThisParameter" when you choose "Copy path" in Firebug's DOM tab:

_options[0].ThisParameter

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

Looking forward to any suggestions, thank you in advance!

share|improve this question

Can you add a hidden input to the form whose values are sent when the Search button is pressed? If you can, what happens when you add <input type='hidden' name='ThisParameter' value='SomethingElse'>? – Stefan Oct 23 at 18:39
@Stefan Unfortunately not, everything is loaded together. But I have tried to do it with Firebug when it's displayed, it's not working. – take2 Oct 23 at 18:43
Who owns the javascript code ? Can't you ask the developer to add your feature ? If you are using a known plugin, can you tell us which it is ? – LeGEC 21 hours ago
feedback

This question has an open bounty worth +50 reputation from take2 ending in 15 hours.

This question has not received enough attention.

2 Answers

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

  1. You have to try to give the script the correct input and hope it uses your value.
  2. Add a script to the results page which will read the url and arguments, change it and redirect, as we discussed here. (If you put everything in functions it should not conflict with the dynamic script if the functions are uniquely named.)

You could try adding something like this jQuery code to the page with 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();
});
share|improve this answer
There are no form tags, only fieldset. There is no unique ID, they change on every page load. Only thing unique is the class of the button and of the DIV that contains the HTML output. – take2 Oct 23 at 19:12
I have edited the code a bit, maybe it's easier to understand now. I thought that this will be much easier than the previous question, but it obviously isn't :/ – take2 Oct 23 at 19:17
@take2: OK, sounds like the javascript/jquery fires on the search button click event, reads the fieldset inputs, creates a search url, then sends the values to the remote url via AJAX, and on succesfull callback the output div gets loaded. But I don't understand what you are actually able to edit? Where are you able to add HTML or javascript or php code (or whatever), in this process? – Stefan Oct 23 at 19:25
My js knowledge is modest, but I think it's like that. I can try to find the click event in the DOM... I just use one line of code do "call" the script and then it gets displayed dynamically. No script control, no HTML control. I get the output and that's it when it comes to editing. Therefore these scripts are my only option to edit it. – take2 Oct 23 at 19:29
If one of the fieldset inputs are named "ThisParameter" then we can catch the mousedown or mayb mouseover event of the button and change the value of "ThisParameter", before the other script fires on the click event. – Stefan Oct 23 at 19:34
show 5 more comments
feedback

You can override any js function and method, or wrap you code around it. The easiest thing would be to look at the code you get and once it gets loaded, you re-declare a method with your own functionality.

I you are trying to replace a parameter in a specific jquery request, you can even wrap around the jquerys ajax method:

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 a lot cleaner to override the method that builds the ajax request rather than the ajax request itself.

share|improve this answer
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

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