如何覆盖从另一个脚本加载的变量参数 [英] How to override variable parameter loaded from another script

查看:68
本文介绍了如何覆盖从另一个脚本加载的变量参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本,可以动态加载代码.这是一种搜索引擎.当我按下搜索按钮时,将触发该操作,并打开一个包含许多参数的新页面.

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.

我想在新URL中覆盖用脚本生成的参数之一. JS代码很大而且很难阅读,但是我已经在Firebug DOM编辑器中找到了重要的部分.

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.

这是执行搜索时生成的URL的模式:

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...

我要编辑的是"ThisParameter"并更改其值.这是DOM中我想要做的部分:

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,...}
...

这是在Firebug的DOM选项卡中选择复制路径"时"ThisParameter"的输出:

And this is the output of "ThisParameter" when you choose "Copy path" in Firebug's DOM tab:

_options[0].ThisParameter

我想知道这是否有可能.我认为是这样的事实是,我可以在Firebug中更改此参数,并且效果很好.因此,如果Firebug可以对其进行编辑,则应该有一种方法可以通过另一个脚本来对其进行影响.

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!

推荐答案

由于无法编辑动态脚本,因此具有以下选项:

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

  1. 您必须尝试为脚本提供正确的输入,并希望它使用您的值.
  2. 如我们在此处. (如果将所有内容都放在函数中,则如果函数被唯一命名,则它不应与动态脚本冲突.)
  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.)

您可以尝试使用搜索按钮在页面中添加类似以下jQuery代码的内容:

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();
});

这篇关于如何覆盖从另一个脚本加载的变量参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆